内置函数
1.日期函数1.1 calendar 日历函数,获取日历,使用方法:
import calendar
print(calendar.month(2024,10))
获取日历字符串
October 2024
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
1.2 time:获取当前操作系统的时间
import time
print(time.ctime())
输出:Thu Oct 10 10:54:27 2024
import time
print(time.localtime())
输出:time.struct_time(tm_year=2024, tm_mon=10, tm_mday=10, tm_hour=10, tm_min=55, tm_sec=47, tm_wday=3, tm_yday=284, tm_isdst=0)
time模块中的函数strptime可以将字符串10/10/2024转化为需要的格式值
from time import strptime
t2 = strptime("10/10/2024","%d/%m/%Y")
1.3 列表函数
尾部插入元素:list.append(x)
插入列表元素:list.insert(i,x),原来i位置的元素会往后退
删除列表函数:list.pop(),删除列表最右端元素,list.remove(x),删除最左端第一个x元素,用之前可以用count(x)来判断先,如果是0就不用了
升序排序:list.sort()
降序排序:list.reverse()
1.4 range():创建一个等间隔的序列
range(start,stop,step)