打印
print('Hello')
注释
#
获得输入
input()
询问并获得输入
input(' ')
重复执行20次
for __count in range(20):
pass
使用变量i遍历序列0到10前
for i in range(0, 10):
pass
当0==0时重复执行
while False:
pass
如果什么执行
if False:
pass
if False:#如果
pass
else:#否则
pass
if False:#如果
pass
elif False:#否则如果
pass
else:#否则
pass
退出循环
break
跳过此步,进入下轮循环
continue
try:#尝试
pass
except s:#当发生异常
pass
类型错误TypeError 语法错误SyntaxError 名称错误NameError 索引错误IndexError 导入错误ImportError 系统错误OSError
参数错误ValueError 缩进错误TabError 除零错误ZeroDivisionError 编码错误UnicodeError解码错误UnicodeDecodeError
finally:#最终执行
几的几次方1 ** 1
几除几的余数64 % 10
什么的绝对值abs(( ))
四舍五入3.14 round(3.14)
import random
0到一的随机浮点数random.random()
几到几的随机整数random.randint(1, 100)
几到几的随机浮点数random.uniform(1.234, 3.456)
在列表中随机选择一项random.choice(List)
引号框起为字符串
转化为整数类型int('')
转化为浮点数类型float('')
转化为字符串类型str('')
转化为自定义类型eval('')
确认字符串的长度len('')
把字符串转化为小写字符''.lower()
把字符串转化为大写字符''.upper()
把字符串转化为单词以大写字符开头''.title()
'Hello'是/否存在于'Hello,World' ('Hello' in/not in 'Hello, World')
'Hello'第0项 'Hello'[0]
把'Hello'按'e'分成列表,执行2次 'Hello'.split('e', 2)
使用‘-’将List列表中的项连接成字符串 '-'.join(List)
‘Hello’从第0项到第3项前的子字符串,间隔1 'Hello'[0:3:1]
添加0到List列表末尾 List.append(0)
插入0到List列表的第0项 List.insert(0, 0)
删除List列表第0项 del List[0]
替换List列表第0项为0 List[0] = 0
List列表第0项 List[0]
List列表的长度 len(List)
0在List列表的位置 List.index(0)
0是否/存在于List列表 (0 not in/in List)
List列表从第0项到第3项前的子列表,间隔1 List[0:3:1]
字典‘number’:1 {'number': 1}
设置Dict键‘number’的值为1 Dict['number'] = 1
删除字典Dict中的‘number’ del Dict['number']
字典Dict键的总数 len(Dict)
键‘number’是/否存在Dict ('number' in/not in Dict)
字典Dict键‘number’的值 Dict['number']
定义函数function1
def function1():
pass
返回0 return 0
声明a为全场变量 global a
使用函数function1 function1()
界面
import easygui
询问:‘是否继续?’标题‘Codemao’选项‘是’‘否’的结果
easygui.ynbox('是否继续?', 'Codemao', ('是', '否'))
消息通知‘Hallo’标题'Codemao'按扭‘OK’
easygui.msgbox('Hello', 'Codemao', 'Ok')
class 类名:
pass
名称.类名 = 参数
_init_ ()#初始化函数