常用的内建函数

目录

 

1、abs函数

2、bool函数

3、dir函数

4、eval函数

5、exec函数

6、float函数

7、int函数

8、long函数

9、max和min函数

10、range函数

11、sum函数

12、文件的使用


1、abs函数

abs(10)    abs(-10)

2、bool函数

bool(0)——bool(1)   //只要非0,均返回True

bool(None)和bool('')返回False

3、dir函数

是“directory”的简写,可以返回关于任何值的相关信息。

4、eval函数

evaluate的简写,把一个字符串作为参数并返回它作为一个Python表达式的结果。

eval('print("wow")'):实际上会执行语句print("wow")

eval('10*5'):返回50

5、exec函数

exec函数和eval函数差不多,但它可以运行更复杂的程序。两者的不同在于eval返回一个值,而exec不会。

6、float函数

foat函数把字符串或者数字转换成“浮点数”。

7、int函数

int函数把字符串或者数字转换成整数,这样会把小数点后面的内容丢掉。

int(‘123.456’)是错误的

8、long函数

返回一个对象的长度,对于字符串则返回字符串中的字符个数。

9、max和min函数

numbers = [5, 4, 10, 30, 22]

print(max(numbers))

30

 

strings = 's, t, r, i, n, g, S, T, R, I, N, G'

print(max(strings))

t

10、range函数

range函数实际上返回了一个叫做迭代器的特殊对象,他能重复一个动作很多次。

11、sum函数

把列表中的元素加在一起并返回这个总和。

12、文件的使用

在Windows中打开文件

test_file = open('c:\\test.txt')

text = test_file.read()

print(text)

写入到文件

test_file = open('c:\\myfile.txt','w')

test_file.write('this is my test file')

 

test_file = open('c:\\myfile.txt','w')

test_file.write('What id green and loud? A froghorn!')

test_file.close()

 

 

test_file = open('myfile.txt')

print(test_file.read())

What id green and loud? A froghorn!

posted @ 2018-10-17 14:42  strawqqhat  阅读(278)  评论(0编辑  收藏  举报
#home h1{ font-size:45px; } body{ background-image: url("放你的背景图链接"); background-position: initial; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-origin: initial; background-clip: initial; height:100%; width:100%; } #home{ opacity:0.7; } .wall{ position: fixed; top: 0; left: 0; bottom: 0; right: 0; } div#midground{ background: url("https://i.postimg.cc/PP5GtGtM/midground.png"); z-index: -1; -webkit-animation: cc 200s linear infinite; -moz-animation: cc 200s linear infinite; -o-animation: cc 200s linear infinite; animation: cc 200s linear infinite; } div#foreground{ background: url("https://i.postimg.cc/z3jZZD1B/foreground.png"); z-index: -2; -webkit-animation: cc 253s linear infinite; -o-animation: cc 253s linear infinite; -moz-animation: cc 253s linear infinite; animation: cc 253s linear infinite; } div#top{ background: url("https://i.postimg.cc/PP5GtGtM/midground.png"); z-index: -4; -webkit-animation: da 200s linear infinite; -o-animation: da 200s linear infinite; animation: da 200s linear infinite; } @-webkit-keyframes cc { from{ background-position: 0 0; transform: translateY(10px); } to{ background-position: 600% 0; } } @-o-keyframes cc { from{ background-position: 0 0; transform: translateY(10px); } to{ background-position: 600% 0; } } @-moz-keyframes cc { from{ background-position: 0 0; transform: translateY(10px); } to{ background-position: 600% 0; } } @keyframes cc { 0%{ background-position: 0 0; } 100%{ background-position: 600% 0; } } @keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } } @-webkit-keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } } @-moz-keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } } @-ms-keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } }