单行注释:#print('hello world')
多行注释:'''print('hello world')'''
ascii转字符:>>>chr(65)
'A'
字符转ascii:>>>ord('A')
65
print('%d %.3f' % (a, b)))
多个字符中生成指定数量的随机字符:
random.sample('zyxwvutsrqponmlkjihgfedcba',5)#返回的是列表
'sep'.join()函数:
str = "-";
seq = ("a", "b", "c"); # 字符串序列
print str.join( seq );
结果为a-b-c
random函数:
>>>range(10) # 从 0 开始到 9 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(1, 11) # 从 1 开始到 10 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> range(0, 30, 5) # 步长为 5 [0, 5, 10, 15, 20, 25]
>>> range(0, 10, 3) # 步长为 3 [0, 3, 6, 9]
>>> range(0, -10, -1) # 负数 [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> range(0)
[]
>>> range(1, 0)
[]
import random
s='hello'
for i in random(len(s)):
print(s[i])
>>>l = [i for i in range(4)]
[0,1,2,3]
bool()函数 空时为false,非空时为true