Python作业

Day13 作业

2019-08-07  本文已影响0人  风月辞寒

1.常用的math模块中的方法

"""______lxh______"""

from time import *

print(math.e)   # 自然常数

print(math.pi)  # 圆周率

print(math.degrees(pi/2))    # 弧度转度
print(math.radians(45))      # 度转弧度

print(math.sqrt(9))          # 平方根

print(math.factorial(10))    # 阶乘

print(math.hypot(3, 4))      # 求直角三角形斜边

print(math.ldexp(3, 9))      # 求3 * 2的9次方

print(math.erf(5))           # 误差函数
print(math.erfc(5))          # 余误差函数

print(math.gamma(5))         # 伽马函数
print(math.lgamma(5))        # 绝对值的自然对数的伽玛函数

2.常用的calendar模块中的方法

"""______lxh______"""

from calendar import *
# 0是星期一,…,6为星期日

print(isleap(2000))     # 是否是闰年

print(leapdays(2000, 2019))     # 判断年份间的闰年数

print(weekday(2019, 8, 7))      # 判断日期为星期几

print(weekheader(0))        # 返回包含星期的英文缩写,n表示英文缩写所占的宽度(0~3)

print(monthcalendar(2019, 8))   # 返回一个月中天数列表

print(prmonth(2019, 8))    # 月历
print(month(2019, 8))    # 月历(多行字符串)
print(prcal(2019, c=2, m=6))    # 年历
print(calendar(2019, c=2, m=6))    # 年历(多行字符串)

print(timegm((2019, 8, 7, 19, 28, 0)))  # 将指定时间转为时间戳

3.常用的time模块中的方法

"""______lxh______"""

from time import *


time1 = time()       # 返回时间戳
print(ctime())      # 打印本地可读时间字符串
time2 = localtime(time1)    # 返回时间戳对应的时间元组
time3 = gmtime(time1)       # 返回格林威治天文时间下的时间元组   有时差
print(ctime())
sleep(2)        # 停止秒数
print(ctime())
print(time1)
print(time2)
print(time3)
print(asctime(time2))       # 返回一个可读形式的时间字符串
print(strftime('%c', time2))  # 获得指定格式的时间

"""
格式符 说明(默认 %c 标准时间格式)  %Y-%m-%d %H:%M:%S 也比较常用
%a    星期的英文单词的缩写:如星期一, 则返回 Mon
%A    星期的英文单词的全拼:如星期一,返回 Monday

%b    月份的英文单词的缩写:如一月, 则返回 Jan
%B    月份的引文单词的缩写:如一月, 则返回 January

%c    返回datetime的字符串表示,如03/08/15 23:01:26

%d    返回的是当前时间是当前月的第几天

%f    微秒的表示: 范围: [0,999999]

%H    以24小时制表示当前小时
%I    以12小时制表示当前小时

%j    返回当天是当年的第几天 范围[001,366]

%m    返回月份 范围[0,12]
%M    返回分钟数 范围 [0,59]

%P    返回是上午还是下午–AM or PM

%S    返回十进制的秒数 范围 [0,61]

%U    返回当周是当年的第几周 以周日为第一天
%W    返回当周是当年的第几周 以周一为第一天

%w    当天在当周的天数,范围为[0, 6],6表示星期天

%x    日期的字符串表示 :03/08/15
%X    时间的字符串表示 :23:22:08
%y    两个数字表示的年份 15
%Y    四个数字表示的年份 2015
%z    与utc时间的间隔 (如果是本地时间,返回空字符串)
%Z    时区名称(如果是本地时间,返回空字符串)
"""

4.常用的os模块中的方法

"""______lxh______"""

from os import *

print(name)     # 获取操作系统平台

print(getcwd())   # 获取现在的工作目录

print(getenv('path'))   # 读取环境变量

print(listdir('animal'))    # 目录下的所有文件名

# system(command)   运行shell命令

print(curdir)   # 返回当前目录

# chdir(dirname)    改变工作目录到dirname

print(path.isfile('animal'))    # 检验给出的路径是不是文件
print(path.isdir('animal'))    # 检验给出的路径是不是目录

print(path.exists('animal'))        # 检验路径是否存在

print(path.dirname('animal'))   # 检验路径是否存在

print(path.join('animal', 'cat'))   # 连接文件名或目录名

print(path.splitext('files/test.txt'))   # 分离扩展名返回二元组
print(path.split('files/test.txt'))   # 分离文件名与目录名返回二元组

print(path.abspath('files/test.txt'))    # 获取绝对路径

print(path.getsize('files/test.txt'))   # 获取文件大小, 是目录返回OL

print(path.getmtime('files/test.txt'))   # 返回文件或目录的最后修改时间
print(path.getatime('files/test.txt'))      # 返回文件或目录的最后访问时间
print(path.getctime('files/test.txt'))      # 返回文件或目录得创建时间

print(sep)          # 系统路径分隔符
print(set(linesep))     # 行终止符
print(extsep)       # 文件与扩展名分隔符

5.sys模块中常用的方法

"""______lxh______"""

from sys import *

print(argv)  # 程序本身路径

print(modules)  # 打印所有已经导入的模块字段
print(modules.keys())  # 模块名
print(modules.values())  # 模块

print(exc_info())  # 获取正在处理的异常

print(hexversion)  # 获取解释器16进制版本信息
print(version)  # 获取解释器版本信息

print(maxsize)  # 返回最大的int值

print(maxunicode)  # 返回最大的Unicode值

print(path)  # 返回模块的搜索路径

print(platform)  # 操作系统平台名称

print(exec_prefix)  # 返回平台独立的python文件安装的位置

print(copyright)  # 记录 python  版权相关的东西

print(api_version)  # 解释器的 C 的 API 版本

print(version_info)  # 以元组返回版权要求

exit()  # 退出程序

上一篇下一篇

猜你喜欢

热点阅读