Python对格式要求严格,尤其注意大小写、冒号及四个空格问题
(Python无switch)
大部分函数用法与其他语言中一致
条件函数:if-else,if-elif-else
循环函数:while-else,for-in-
break:从for或while循环中中断运行,进入else
continue:跳出当前循环,继续下一轮循环
len( ) 计算字符串、列表等的元素个数
range(0,9,2) 输出数列,起始值0,结束值9(不包括9),间隔(步长)为2
def fun( ): 定义函数
return 返回值
input( )、print( ) 输入输出值
int、float、complex 常用数据类型
type( ) 查看当前对象的类型
\ 转义符
r'str' 自然运算符(避免出现多个\)
in、not in
help( ) 查找系统函数
find( ) 返回(首字母 )所在位置
split( ) 切割字符串,返回列表
join( ) 组合字符
栗子:
ip='192.168.1.2'
ip2=ip.split('.') ## ['192', '168', '1', '2']
ip3='.'.join(ip2) ## '192.168.1.2'
%传值
say='there are %d monkeys in the %s' ## %d 对应数字,%s 对应字符串
say%(3,'tree')
注释:单行#,多行三引号、ctrl+'/' (mac: command+'/')