调用函数
python中内置了许多函数,我们可以直接调用,但需要注意的是参数的个数和类型一定要和函数一致,有时候不一致时,可以进行数据类型转换
1.abs()函数【求绝对值的函数,只接受一个参数】
#求a的绝对值
>>>a = -200
>>>b = 200
>>>c = abs(a)
>>>print(c)
>>>print(b)
200
200
2.max()函数【求最大值函数,接受多个参数,返回最大值】
>>>a = max(1,2,3,4,-3,9)
>>>print(a)
9
3.数据类型转换简介【比如int()
函数可以把其他数据类型转换为整数】
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a = int('123')
b = int(11.21)
c = float('11.21')
d = str(1.24)
e = bool(1)
f = bool('')
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)
# -*- coding: utf-8 -*-
a = int('123')
b = int(11.21)
c = float('11.21')
d = str(1.24)
e = bool(1)
f = bool('')
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)