-
add適合于單個元素
update適合于集合
查看全部 -
#?3-1?Python?基礎數據類型 print(type(3.1415926)) print(type('hello?world')) print(type(100)) print(type(0b1101))
查看全部 -
python包含數據類型:整數 浮點數? 字符串 布爾值 空值查看全部
-
短路計算
在計算a and b時,如果 a 是 False,則根據與運算法則,整個結果必定為 False,因此返回 a;如果 a 是 True,則整個計算結果必定取決與 b,因此返回 b。
在計算a or b時,如果 a 是 True,則根據或運算法則,整個計算結果必定為 True,因此返回 a;如果 a 是 False,則整個計算結果必定取決于 b,因此返回 b。查看全部 -
age=19
if age>=18
??? print ('adult'+str(age))
查看全部 -
#對漢字表示的數字也可分辨 def?is_number(s): ????try:??#?如果能運行float(s)語句,返回True(字符串s是浮點數) ????????float(s) ????????return?True ????except?ValueError:??#?ValueError為Python的一種標準異常,表示"傳入無效的參數" ????????pass??#?如果引發了ValueError這種異常,不做任何事情(pass:不做任何事情,一般用做占位語句) ????try: ????????import?unicodedata??#?處理ASCii碼的包 ????????for?i?in?s: ????????????unicodedata.numeric(i)??#?把一個表示數字的字符串轉換為浮點數返回的函數 ????????????#return?True ????????return?True ????except?(TypeError,?ValueError): ????????pass ????return?False
查看全部 -
T = (1, 'CH', [3, 4])
Z=list(T)
Z[2]=tuple(Z[2])
T=tuple(Z) #這個T可以是任何字符
print(T)
查看全部 -
T = ((1+2), ?((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
print(T) # ==>
(3, (3,), 'ab', (1,), (1, 2, 3, 4, 5))
('a'+'b')=ab,所以共3個
查看全部 -
print((100, 69, 29, 100, 72, 99, 98, 100, 75, 100, 100, 42, 88, 100).count(100))
查看全部 -
a=inpult("請輸入一個數")
b=inpult("請輸入一個數")
c=a*b
print(c)查看全部 -
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
num=0
v1=v2=v3=1
while num<=2:
? ? v1=v1*L[0][num]
? ? v2=v2*L[1][num]
? ? v3=v3*L[2][num]
? ? num=num+1
print(v1)
print(v2)
print(v3)
查看全部 -
L2=[89, 72, 88, 79, 99]
L=zip(L2,L1)
Z=sorted(L,key=lambda s:s[0])
P=(s for _,s in Z)
print(list(P))
查看全部 -
L=['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.insert(5,'Gen')
L.insert(6,'Phoebe')
L.insert(7,'Zero')
print(L)
查看全部 -
L=['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Gen')
L.append('Phoebe')
L.append('Zero')
print(L)
查看全部 -
L = [95.5, 85, 59, 66, 72]
L.sort()
print(L[-1],L[-2],L[-3])
查看全部 -
L = ['Alice', 66, 'Bob', True, 'False', 100]?
num=0
for ou in L:
? ? num=num+1
? ? if round(num%2)==0:
? ? ? ? print(ou)
查看全部 -
L = ['Alice', 66, 'Bob', True, 'False', 100]?
num=0
for ou in L:
? ? num=num+1
? ? if round(num%2)==0:
? ? ? ? print(ou)
查看全部
舉報