变量及数据类型
Python当中一切皆对象,变量也是对象,u有自己的属性和方法。
Boolean
Integer
Float
String
List–>[12,string]//列表
Tuple–>(12,string)//元组
Dict -->dist={‘Bob’:18,‘Lucy’:16}字典
Set–>([12,string])
字符串和列表的转换
字典的使用
字典名={‘关键字’:值,…}
字典名.get(‘关键字’,默认值)
字典名[‘关键字’]=值
字典名.copy()//复制
字典名.popitem()//弹出
Python表达式
and 逻辑与(串联)
or 逻辑或(并联)
not 逻辑非
eg:if 22 and 12:
print (“holle”)
else:
print(“holle”)
if 22 or 12:
print (“holle”)
else:
print(“holle”)
if not 2==2:
print (“holle”)
else:
print(“holle”)
=========================== RESTART: D:\python\eg.py ===========================
holle
holle
holle
逻辑分支
当判定条件为True时执行特定语句
1)if 条件判断语句:
…
else:
…
2)if 条件判断语句:
…
elif 条件判断语句:
…
else:
…
Python当中没有switch语句
没有三元运算符 food?eat=1:eat=0;
循环
重复执行特定语句
For循环
for 变量in 列表:
…
循环控制语句:
continue:执行下一循环
break:跳出循环
else:正常完成循环时执行
While循环
while 判断条件:
…
迭代器
for i in range(10):
if i>5 and i<8:
coutinue
print (i)
=========================== RESTART: D:\python\eg.py ===========================
0
1
2
3
4
5