第二節練習

2021-10-19 09:35:39 字數 3787 閱讀 4686

a=b=

2# 鏈式賦值

print

(a)print

(b)c=

id(a)

#位址print

(c)c=

type

(a)#型別

print

(c)a,b=2,

3# 系列解包賦值

a,b=b,a

print

(a)print

(b)# 基本運算

print(3

+2)print(30

-5)print(30

/5)print(30

//5)print(5

*6)print(7

%4)print(2

**3)a=

divmod(13

,3)print

(a)print()

# int()實現型別轉換

a=int

(3.14

)print

(a)a=

float(3

)print

(a)print

(round

(3.14))

# 增強型賦值運算子

a+=2

print

(a)a-=

2print

(a)a*=

2print

(a)a/=

2print

(a)a//=

2print

(a)a**=

2print

(a)a%=

2print

(a)#計算當前時間

import time

a=time.time(

)print

(a)b=a//

60print

(b)print

(int

(b))

print

(int

(b)//

60//24)

# 畫折現,計算距離

import turtle

import math

x1,y1=

100,

100x2,y2=

200,

100x3,y3=

500,

200x4,y4=

400,

50turtle.goto(x1,y1)

turtle.goto(x2,y2)

turtle.goto(x3,y3)

turtle.goto(x4,y4)

distance=math.sqrt(

(x4-x1)**2

+(y4-y1)**2

)print

(distance)

#布林值運算b=2

+true

print

(b)#比較運算子

a,b=10,

20print

(a==b)

print

(a!=b)

print

(a>b)

print

(aprint

(a>=b)

print

(a<=b)

#邏輯運算子

a=true

b=false

print

(a or30)

print

(a or30/

0)print

(b or30)

print

(a and30)

print

(b and30)

#同一運算子

a,b=

111,

111print(id

(a))

print(id

(b))

print

(a==b)

print

(a is b)

a,b=

1111

,1111

print(id

(a))

print(id

(b))

print

(a==b)

print

(a is b)

# 字串編碼

print

(ord

("高"))

print

(chr

(10300))

a="i am a teacher!"

print

(a)a=

'i am a "tom"'

print

(a)a=

'''name="liang"

***="famale" age=18'''

print

(a)c=

""print

(len

(c))

a="i\nlove\nyou"

print

(a)a=

"i\'m a teacher"

print

(a)a=

"aaa"

+"bbb"

print

(a)a=

"aaa"

"bbb"

print

(a)a=

"aaa"*3

print

(a)print

("aa"

,end=

"*")

print

("bb"

,end=

"*")

print

("cc"

)myname=

input

("請輸入你的名字:"

)"""

a=str

(3.14

)print

(a[-1]

)print

(a.replace(

".",

"高")

)print

(a[:])

print

(a[1:3

])print

(a[-2:

-5:1

])a=" to be or not to be"

print

(a[::-

1])a=

"sxt"*5

print

(a)print

(a[0::

3])a=

["to"

,"you"

]print

(a)print

('*'

.join(a)

)a,b=

"abd_33"

,"abd_33"

print

(a is b)

a,b=

"abd#"

,"abd#"

print

(a is b)

print(id

(a))

print(id

(b))

print

(a==b)

print

("a"

in a)

print

("ddd"

in a)

a="名字是,年齡是"

b=a.

format

("小明",20

)print

(b)a=

"名字是,年齡是"

b=a.

format

(name=

"小明"

,age=20)

print

(b)

彙編 第二節

第二節 cpu主要有有運算器,控制器,暫存器,三部分組成 8086 cpu有14個暫存器,如ax,bx,cx,dx,si。8086所有暫存器都是16位的,可以存放2個byte即位元組,16位二進位制數 所能存放的最大數值是 11111111111 2 16 1 從0開始,所以 1嘛 通用暫存器為4個...

函式第二節

coding utf 8 1.定義乙個方法get num num num引數是列表型別,判斷列表裡面的元素為數字型別。其他型別則報錯,並且返回乙個偶數列表 注 列表裡面的元素為偶數 def get num l l for i in l 判斷列表l的元素是否都為整形 if not isinstance...

物件導向第二節

coding utf 8 定義乙個列表的操作類 listinfo 包括的方法 1 列表元素新增 add key keyname keyname 字串或者整數型別 2 列表元素取值 get key num num 整數型別 3 列表合併 update list list list 列表型別 4 刪除並...