1. 标识符、关键字
if/else/elif/break/continue/for/while/and/or/not/in/True/False/try/except/finally/as/import/from/def/class/return/Noneglobal/lambda2. 变量、输入、输出
a =100 引用
a =4
b =5
c = a
a = b
b = c
a = a+b
b = a-b
a = a-b
a,b = b,a
python2
a =input()#3+4----->a = 7raw_input()
python3
a =input()#3+4 ---->a = "3+4"#100--->a = "100"int("100")--->100str(100)---->"100"33670--->str(33670)--->"33670"--->len("33670")--->53. 字符串、列表、元组、字典、集合、列表生成式、类型转换
"aaa"'sdfsdf'
a ="abcd"
a[:3]---->"abc"
a[::-1]---->"dcba"[1,2,3,1,1,1]--->增删改查
(1,2,3,1,1,1)-->只读
{1,2,3,1,1,1}---->{1,2,3} 集合---元素不重复
字典---->{key:value, key2:value}
可变类型:列表、字典、集合
不可变类型:数字、字符串、元组
["aa","ddd"]{"name":"asdf","age":10}[{"name":"xxx","family":[{"小姑":"aa","family":["a","b","cc"]},"bb","ccc"]},{},{}]
a =[111,22,33,1,111,111,111,343]
b =set(a)
c =list(b)
d =tuple(a)"a"+"b"---->"ab"4. 切片
顺序、选择、循环
5.ifif 条件:
xxxx
if 条件:
xxxx
else:
xxxx2
if 条件1:
xxx1
elif 条件2:
xxx2:elif 条件3:
xxxx3
.....else:
xxxx
if xxx:
xxx
xxx
xx
if yyy:
yyyyy1
6.while
i =0while i<100:
xxxx
xxx
xxx
i+=1
i =100while i>0:print(i)
i-=1whileTrue:passwhile xxx:while yyy:pass7.for
a =[111,22,33]for i in a:
xxxxx
8. 各种嵌套
9. 函数、参数、返回值、全局/局部变量、多个return、一个return返回多个值
defxxx(形参):
。。。。。
return0return1....return(0,1)return[0,1]
xxx(实参)
结束一个函数:return
结束一个循环:break/continue
结束一个程序:exit()deftest(a,b,c=100,*args,**kwargs):pass
test(b=11,a=22,100,200,300,400,mm=100,nn=20)
num =100deftest():global num
num=20010. 类、对象
classAnimal(父类):
类属性
num =100
实例方法
def__init__(self):
self.xxx =100 实例属性
父类名字.父类方法(self)super().父类的方法名()super(当前类的名字Animal,self).父类的方法名()
实例方法
deftset(self):
Animal.num =300
类方法
@classmethoddefxxx(cls):
cls.num =200
静态方法
@staticmethoddefyyy():pass
a = Animal()
b = a
del a----->不会调用__del__
del b----->调用__del__方法
11. 异常
try:
xxxx
except 异常的名字:
异常的处理。。。。
else:
没有异常的时候执行
finally:
不管有没有产生异常,都会执行
12. 模块、包
import 模块、包xxxx
xxxx.功能()from 模块 import test1,test2
test1()from....import*if __name__ =="__main__":
xxx