Day13 作業(yè)

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

"""______lxh______"""

from time import *

print(math.e)   # 自然常數(shù)

print(math.pi)  # 圓周率

print(math.degrees(pi/2))    # 弧度轉(zhuǎn)度
print(math.radians(45))      # 度轉(zhuǎn)弧度

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))           # 誤差函數(shù)
print(math.erfc(5))          # 余誤差函數(shù)

print(math.gamma(5))         # 伽馬函數(shù)
print(math.lgamma(5))        # 絕對(duì)值的自然對(duì)數(shù)的伽瑪函數(shù)

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

"""______lxh______"""

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

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

print(leapdays(2000, 2019))     # 判斷年份間的閏年數(shù)

print(weekday(2019, 8, 7))      # 判斷日期為星期幾

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

print(monthcalendar(2019, 8))   # 返回一個(gè)月中天數(shù)列表

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)))  # 將指定時(shí)間轉(zhuǎn)為時(shí)間戳

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

"""______lxh______"""

from time import *


time1 = time()       # 返回時(shí)間戳
print(ctime())      # 打印本地可讀時(shí)間字符串
time2 = localtime(time1)    # 返回時(shí)間戳對(duì)應(yīng)的時(shí)間元組
time3 = gmtime(time1)       # 返回格林威治天文時(shí)間下的時(shí)間元組   有時(shí)差
print(ctime())
sleep(2)        # 停止秒數(shù)
print(ctime())
print(time1)
print(time2)
print(time3)
print(asctime(time2))       # 返回一個(gè)可讀形式的時(shí)間字符串
print(strftime('%c', time2))  # 獲得指定格式的時(shí)間

"""
格式符 說明(默認(rèn) %c 標(biāo)準(zhǔn)時(shí)間格式)  %Y-%m-%d %H:%M:%S 也比較常用
%a    星期的英文單詞的縮寫:如星期一, 則返回 Mon
%A    星期的英文單詞的全拼:如星期一,返回 Monday

%b    月份的英文單詞的縮寫:如一月, 則返回 Jan
%B    月份的引文單詞的縮寫:如一月, 則返回 January

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

%d    返回的是當(dāng)前時(shí)間是當(dāng)前月的第幾天

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

%H    以24小時(shí)制表示當(dāng)前小時(shí)
%I    以12小時(shí)制表示當(dāng)前小時(shí)

%j    返回當(dāng)天是當(dāng)年的第幾天 范圍[001,366]

%m    返回月份 范圍[0,12]
%M    返回分鐘數(shù) 范圍 [0,59]

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

%S    返回十進(jìn)制的秒數(shù) 范圍 [0,61]

%U    返回當(dāng)周是當(dāng)年的第幾周 以周日為第一天
%W    返回當(dāng)周是當(dāng)年的第幾周 以周一為第一天

%w    當(dāng)天在當(dāng)周的天數(shù),范圍為[0, 6],6表示星期天

%x    日期的字符串表示 :03/08/15
%X    時(shí)間的字符串表示 :23:22:08
%y    兩個(gè)數(shù)字表示的年份 15
%Y    四個(gè)數(shù)字表示的年份 2015
%z    與utc時(shí)間的間隔 (如果是本地時(shí)間,返回空字符串)
%Z    時(shí)區(qū)名稱(如果是本地時(shí)間,返回空字符串)
"""

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

"""______lxh______"""

from os import *

print(name)     # 獲取操作系統(tǒng)平臺(tái)

print(getcwd())   # 獲取現(xiàn)在的工作目錄

print(getenv('path'))   # 讀取環(huán)境變量

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

# system(command)   運(yùn)行shell命令

print(curdir)   # 返回當(dāng)前目錄

# chdir(dirname)    改變工作目錄到dirname

print(path.isfile('animal'))    # 檢驗(yàn)給出的路徑是不是文件
print(path.isdir('animal'))    # 檢驗(yàn)給出的路徑是不是目錄

print(path.exists('animal'))        # 檢驗(yàn)路徑是否存在

print(path.dirname('animal'))   # 檢驗(yàn)路徑是否存在

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

print(path.splitext('files/test.txt'))   # 分離擴(kuò)展名返回二元組
print(path.split('files/test.txt'))   # 分離文件名與目錄名返回二元組

print(path.abspath('files/test.txt'))    # 獲取絕對(duì)路徑

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

print(path.getmtime('files/test.txt'))   # 返回文件或目錄的最后修改時(shí)間
print(path.getatime('files/test.txt'))      # 返回文件或目錄的最后訪問時(shí)間
print(path.getctime('files/test.txt'))      # 返回文件或目錄得創(chuàng)建時(shí)間

print(sep)          # 系統(tǒng)路徑分隔符
print(set(linesep))     # 行終止符
print(extsep)       # 文件與擴(kuò)展名分隔符

5.sys模塊中常用的方法

"""______lxh______"""

from sys import *

print(argv)  # 程序本身路徑

print(modules)  # 打印所有已經(jīng)導(dǎo)入的模塊字段
print(modules.keys())  # 模塊名
print(modules.values())  # 模塊

print(exc_info())  # 獲取正在處理的異常

print(hexversion)  # 獲取解釋器16進(jìn)制版本信息
print(version)  # 獲取解釋器版本信息

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

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

print(path)  # 返回模塊的搜索路徑

print(platform)  # 操作系統(tǒng)平臺(tái)名稱

print(exec_prefix)  # 返回平臺(tái)獨(dú)立的python文件安裝的位置

print(copyright)  # 記錄 python  版權(quán)相關(guān)的東西

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

print(version_info)  # 以元組返回版權(quán)要求

exit()  # 退出程序

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容