函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#python自带函数
#函数
#abs绝对值
abs(10)
a = abs(-100)
print a
#最大值
m = max(1,2,3,4,5)
print m
#数据类型转换
print int('120')
print int(123.12)
print str(123)
print bool(1)
print bool(0)
#引用,相当于给abs起了一个别名
a = abs
print a(-1)
#hex转成十六进制
#isinstance参数类型检查
#raise抛出异常
def (x):
if not isinstance(x,(int,float)):
raise TypeError('Bad operand type')
if x>0:
return x
else:
return -x
print my_abs(99)
#pass为空函数,没有空函数的话报错
c = 1
if c>18:
pass