CONTENTS
str 和 bytes 相互转换
# bytes object b = b"example" # str object s = "example" # str to bytes bytes(s, encoding = "utf8") # bytes to str str(b, encoding = "utf-8") # str to bytes str.encode(encoding = "utf8") # bytes to str bytes.decode(encoding = "utf8")
str 和 int 相互转换
字符串str转换成int: int_value = int(str_value) int转换成字符串str: str_value = str(int_value)
简单的正则表达式
import re; tempture = re.search(r"t=[0-9]{3,}", "70 01 4b 46 7f ff 10 10 e1 t=23000"); tempture = tempture.group(0); tempture = tempture[2:];
获取版本号码
import platform platform.python_version()
生成随机数
import random random.randint(30,60)
时间
import time time.strftime("%S", time.localtime()) %y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数(0-23) %I 12小时制小时数(01-12) %M 分钟数(00=59) %S 秒(00-59) %a 本地简化星期名称 %A 本地完整星期名称 %b 本地简化的月份名称 %B 本地完整的月份名称 %c 本地相应的日期表示和时间表示 %j 年内的一天(001-366) %p 本地A.M.或P.M.的等价符 %U 一年中的星期数(00-53)星期天为星期的开始 %w 星期(0-6),星期天为星期的开始 %W 一年中的星期数(00-53)星期一为星期的开始 %x 本地相应的日期表示 %X 本地相应的时间表示 %Z 当前时区的名称 %% %号本身
发表评论