python基础语法
1 2 3 4
| age = 20 1+1 print('Hello World!')
|
1 2 3 4 5
| if 1 == 2: print("假的") else: print("1==2是假的")
|
1 2 3
| for i in range(5): print(i)
|
1 2 3 4 5 6 7
| sum = 0 n = 99 while n > 0: sum = sum + n n = n - 1 print(sum)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
n = 1 while n <= 100: if n > 10: break print(n) n += 1 1 2 3 4 5 6 7 8 9 10
|
1 2 3 4 5 6 7 8 9 10 11
| n = 1 while n < 10: n = n + 1 if n % 2 == 0: continue print(n) 3 5 7 9
|
1 2 3 4 5 6 7 8 9 10 11 12
| for letter in 'Room': if letter == 'o': pass print('pass') print(letter) R pass o pass o m
|
1 2 3 4 5 6 7
|
a = 3 b = 3.14 c = 3 + 4j print(type(a), type(b), type(c)) <class 'int'> <class 'float'> <class 'complex'>
|
1 2 3 4 5 6 7
|
a = "Hello" b = "Python" print("a + b 输出结果:", a + b)
a + b 输出结果: HelloPython
|
1 2 3 4 5 6 7 8 9
|
list = ['abcd', 786 , 2.23, 'runoob', 70.2] print(list[1:3])
[786, 2.23]
|
1 2 3 4 5 6 7 8 9
|
t1 = ('abcd', 786 , 2.23, 'runoob', 70.2) t2 = (1, ) t3 = ('a', 'b', ['A', 'B']) t3[2][0] = 'X' print(t3) ('a', 'b', ['X', 'B'])
|
1 2 3 4 5 6 7
|
d = {'Michael': 95, 'Bob': 75, 'Tracy': 85} print(d['Michael']) 95
|
1 2 3 4 5 6
|
s = set([1, 1, 2, 2, 3, 3]) print(s) {1, 2, 3}
|
原文地址:https://aistudio.baidu.com/aistudio/projectdetail/415810?pV=75981