0
点赞
收藏
分享

微信扫一扫

Springboot 使用JavaMailSender发送邮件 + Excel附件

模块


内置模块

random

random.random( )

>>> random.random()
0.364183511476754

random.randint(n,m)

>>> random.randint(5,10)
7

random.randrange(n,m)

>>> random.randrange(1,10)
3
>>> random.randrange(1,10)
1


>>> random.randrange(0,1)   #左闭右开,所以永远取不到1
0
>>> random.randrange(0,1)
0
>>> random.randrange(0,1)
0

>>> random.randrange(1,10,2)  #步长为2,所以从1起步只能取1,3,5,7,9
5
>>> random.randrange(1,10,2)
9
>>> random.randrange(0,10,2)  #步长为2,所以从0起步只能取0,2,4,6,8
2
>>> random.randrange(0,10,2)
4
>>>

random.uniform(n,m) 

>>> random.uniform(0,1)
0.8341113837892614
>>> random.uniform(0,0)  #可以看出是[n,m]的
0.0
>>> random.uniform(0,100)
66.47340671952776
>>>

random.choice([元素1,元素2,元素3,元素4]) 

>>> random.choice([1,2,3,4,5])
5
>>> random.choice([1,2,3,4,5])
4
>>> random.choice([1,2,3,4,5])
1
>>>

random.shuffle(列表)

>>> list1 = [1,2,3,4,5,6]
>>> random.shuffle(list1)
>>> list1
[4, 1, 6, 3, 2, 5]
>>>

math

math.e、math.pi(π)

>>> math.e
2.718281828459045
>>> math.pi
3.141592653589793
>>>

math.ceil(浮点型数字)

>>> math.ceil(3.00001)
4
>>> math.ceil(3.00000000000001)
4
>>> math.ceil(3.000000000000000000000001)   #注意:取整还是有一定限度的
3

math.floor(浮点型数字)

>>> math.floor(3.99999)
3
>>> math.floor(3.9999999999999)
3
>>> math.floor(3.99999999999999999999999)  #同理,也是有一定限度的
4
>>>

round(浮点型数字)

>>> round(4.5)    #整数为偶数遵循以五为界限,五会被舍弃(即不进位)
4
>>> round(5.5)    #整数为奇数遵循标准的四舍五入
6

>>> round(4.6)    #其余皆遵循四舍五入
5
>>> round(4.4)
4
>>> round(5.6)
6
>>> round(5.4)
5
>>>

math.pow(被次方数,次方数)

>>> math.pow(2,3)
8.0
>>> math.pow(2,4)
16.0
>>>

math.sqrt(被开平方数)

>>> math.sqrt(9)
3.0
>>> math.sqrt(4)
2.0
>>> math.sqrt(8)
2.8284271247461903
>>>

math.fabs(数字)

>>> math.fabs(-11)
11.0
>>> math.fabs(11)
11.0
>>> math.fabs(-11.11)
11.11
>>> math.fabs(11.11)
11.11
>>>

abs(数字)

>>> abs(-11.11)
11.11
>>>

math.log(对数,底数)

>>> math.log(8,2)
3.0
>>> math.log(math.e,math.e)  #要用e,必须要加math
1.0
>>> math.log(8)    #默认以e为底
2.0794415416798357
>>>

os

os.cpu_count()

>>> os.cpu_count()
20

os.curdir

>>> os.curdir
'.'          #当前文件,相对路径
>>>

 os.path.abspath(os.curdir)

>>> os.path.abspath(os.curdir)
'C:\\Users\\朱俊杰'
>>>

os.chdir()

>>> os.path.abspath(os.curdir)
'C:\\Users\\朱俊杰'
>>> os.chdir("../")    #../为返回上一级目录
>>> os.path.abspath(os.curdir)
'C:\\Users'
>>>

os.chmod()

os.getcwd()

>>> os.getcwd()
'C:\\Users'
>>>

os.getpid()

>>> os.getpid()
26460

os.getppid()

>>> os.getppid()
23280
>>>

os.mkdir()

os.makedirs()

os.name

>>> os.name
'nt'       #代表是windows
>>>

os.remove()

os.rename()

os.system("cls")

os.sep

>>> os.sep
'\\'
>>>

os.listdir([path])

>>> os.listdir(".")
['All Users', 'Default', 'Default User', 'desktop.ini', 'GLCache', 
'Public', '朱俊杰', '鏈变繆鏉', '鏈变繆鏉癨AppData']
>>> os.listdir("d:\\")
['$RECYCLE.BIN', '.idea', '73fee546e6777c712160fd43cddcd773', 
'BaiduNetdiskDownload', 'BaiduSyncdisk', 'Config.Msi', 'c 语言', 
'edge下载', 'ensp', 'JAVA', 'kali', 'Program Files', 'pycharm', 
'python', 'steam', 'System Volume Information', 'venv', 'vmware',
 'WindowsApps', 'winrar', 'WpSystem', 'WUDownloadCache', 'xlj', 
'云计算', '云计算1', '夸克网盘', '奖学金', '学校', '有道云笔记', 
'比特', '火狐下载', '腾讯会议', '腾讯会议录频', '谷歌下载', '软件', 
'配音', '金山打字通', '钉钉']
>>>

os.scandir([path])

>>> a = os.scandir("d:\\")
>>> for i in a:
...     print(i)
...
<DirEntry '$RECYCLE.BIN'>
<DirEntry '.idea'>
<DirEntry '73fee546e6777c712160fd43cddcd773'>
<DirEntry 'BaiduNetdiskDownload'>
<DirEntry 'BaiduSyncdisk'>
<DirEntry 'Config.Msi'>
<DirEntry 'c语言'>
<DirEntry 'edge下载'>
<DirEntry 'ensp'>
<DirEntry 'JAVA'>
<DirEntry 'kali'>
<DirEntry 'Program Files'>
<DirEntry 'pycharm'>
<DirEntry 'python'>
<DirEntry 'steam'>
<DirEntry 'System Volume Information'>
<DirEntry 'venv'>
<DirEntry 'vmware'>
<DirEntry 'WindowsApps'>
<DirEntry 'winrar'>
<DirEntry 'WpSystem'>
<DirEntry 'WUDownloadCache'>
<DirEntry 'xlj'>
>>>

os.path

path.abspath(目录)

>>> path.abspath(".")
'C:\\Users'
>>>

path.basename(路径)

>>> path.basename("D:\\python\\Day10\\main.py")
'main.py'

path.dirname(路径)

>>> path.dirname("D:\\python\\Day10\\main.py")
'D:\\python\\Day10'
>>>

path.getctime(路径)

path.getmtime(路径)

path.getatime(路径)

path.exists(路径)

>>> path.exists("D:\\python\\Day10\\main.py")
True
>>> path.exists("D:\\python\\Day10\\ma.py")
False
>>>

 path.getsize(路径)

>>> path.getsize(".")
4096

path.isdir()

path.isfile()

path.join(前面路径,后面路径)

>>> f="D:\\python\\Day10\\ma.py"
>>> path.join(f,"a.mp3")
'D:\\python\\Day10\\ma.py\\a.mp3'
>>>

路径拼接第二种方法

>>> f="D:\\python\\Day10\\ma.py"
>>> f + os.sep +"a.mp3"
'D:\\python\\Day10\\ma.py\\a.mp3'
>>>

举报

相关推荐

0 条评论