Python入门随记(3)

1、len()

长度或规模函数

2、Unicode转为单字符用chr()

单字符转为Unicode用ord()

3、关于字符的操作函数

函数 作用
lower() 变为小写
upper() 变为大写
split() 分割字符串
count() 某字符数
replace() 替换
center() 填充至居中
strip() 删除字符
join() 合并字符

例:

print('An official account of WeChat, called pygis.'.count('a'))

4、格式化的字符串

"{}   ".format()

5、time

关于时间操作

例:

time.sleep(3)        #程序睡眠3秒

6、写程序的好习惯

擅用try语句

7、random

关于随机数的函数库

8、全局变量用global

9、randint()

随机整数

10、randrange(m,n,k)

随机数,(起始,终止,步长)

pygis,培养思维,分析实践
原文地址:https://www.cnblogs.com/pygisxss/p/14349990.html