类型
- string 字符串 abc 不可变 字符数组
- tuple 元组 (1,2,3) 不可变
- list 列表 [1,2,3] 可变
- set 集合 set(1,2,3) 去重复,集合的一般操作
- number 数字 整型(int) 浮点型(float) 复数(complex)不可变
- dict 字典 {‘a’:1,’b’:2} 键值对 可变
- 检查类型 isinstance(foo,int) type(bar)
条件控制和循环
- if
try:
a=int(input('输入数字'))
if a<0:
print('<0')
elif a>0:
print('>0')
else:
print('=0')
except ValueError:
print('Value Error')
- while
import time
while True:
print('loop')
time.sleep(10)
- for 配合with打开输出文件内容并关闭
def forOpenFile():
with open('test.txt') as f:
for i in f:
print(i)
面向对象
- 类
class Foo:
bar=123
def __init__():
print('init')
def getBar(self):
print(self.bar)
t=Foo()
t.getBar()