Python知识点路线
list_x1 = [6, 5, 8, 9, 0, 3, 6]
list_x2 = [6, 5, 8, 9, 0, 3, 6]
list_x3 = []
list_x4 = []
list_x1.append(list_x2)
for i in range(3):
list_x3.append(i)
for i in range(12, 30,3):
list_x3.append(i)
list_x4 = [i for i in range(20, 30, 2)]
for i in range(5):
list_x3.append(list_x4[i])
print("list_x3[:]: ", list_x3[:])
list_x3 = [i-5 if i >= 5 else i+5 for i in list_x3]
print("list_x3[:]: ", list_x3[:])
j = 0
for i in list_x3:
if i >= 10:
list_x3[j] = i-5
j += 1
else:
list_x3[j] = i+5
j += 1
print("list_x3[:]: ", list_x3[:])
del_idx = list_x3.index(18)
print("18所在位置: ",del_idx)
del list_x3[del_idx]
for i in list_x3:
if i == 10:
list_x3.remove(10)
print("list_x3[:]: ", list_x3[:])
n = len(list_x3)
print("n: ", n)
print(list_x3 + list_x2)
try:
print(list_x3 - list_x2)
except:
print("不存在")
list_x5 = [i * j for i, j in zip(list_x2, list_x3)]
print("list_x5: ", list_x5)
tuple_x = (3.0, "XXX")
print(tuple_x)
tuple_x = tuple_x + (5, 6,)
print(tuple_x)
dict_test = {"1111": "2222", "3333": "4444"}
print(dict_test)
dict_test = dict(zip(list_x2, list_x3))
print(dict_test)
print(dict_test[5])
print(dict_test.get(100, "不存在"))
old_dict = {"name": "Heywhale",
"age": "18"}
new_dict = {'alias': 'Smallwhale',
'name': 'Smallwhale'}
print('更改前:', old_dict)
old_dict.update(new_dict)
print('更改后', old_dict)
print(len(old_dict))
print(type(old_dict))
print(dict_test.keys())
print(dict_test.values())
print(dict_test.items())
x = 3
if x < 2:
score = 6
elif x > 4:
score = 0
else:
score = 2
print(score)
x = True
if x:
print("work")
i, num = 0, 9
while i <= num:
print("i={}".format(i))
i +=1
for i in range(10, 20):
print("i=",i)
list_x = [1, 2, 3, 4, 5]
print('----遍历列表------')
for i in list_x:
print("i={}".format(i))
values = ['a', 'b', 'c', 'd']
keys = [1, 2, 3, 4, 5]
dict_test = dict(zip(keys, values))
print('----遍历字典------')
for k, v in dict_test.items():
print("key = {0}, value = {1}".format(k, v))
print( "今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问何几" )
for number in range(100):
if (number % 3 == 2) and (number % 5 == 3) and (number % 7 == 2): # 判断是否符合条件
print("答曰:这个数是{}".format(number)) # 输出符合条件的数
break # 跳出循环
total = 0 # 用于保存累加和的变量变量
for number in range(1, 100):
if number % 2 == 1: # 判断是否符合条件
continue # 继续下一次循环
total += number # 累加偶数的和
print( "1 到 100 之间(不包括 100)的偶数和为:", total ) # 输出累加的和
for i in range(1, 10):
if i % 2 == 0: # 判断是否为偶数
print(i, end = " ")
else: # 不是偶数
pass # 占位符,不作任何操作
各个基本知识点