函数 调用 abs 即求绝对值 只有一个函数
比较函数 cmp(x,y) 有两个参数 x>y 1 x<y -1 x=y 0
数据类型转化 int()
定义函数 自定义求绝对值的my-abs函数 def my-abs(a):
if a>=0:
return a
else:
return -a

def power(x): def power(x,n):
return x*x s=1
while n>0:
n=n-1
s=s*x
return s 


定义函数名是两个以上单词的,第二个单词首字母要大写
def add():    再次调用时只需输入add()
单独的一个def操作不会出现效果,跟定义一个变量没有差别
# encoding:utf-8
a = 100
def fun():
    if True:
        print "good"
        print a

if fun():
    print "ok"
D:\Python安装程序\python.exe C:/Users/欢/PycharmProjects/untitled/编程.py
good
100

Process finished with exit code 0
# encoding:utf-8
a = 100
def fun():
    if True:
        print "good"
        print a

fun()
fun()
fun()
D:\Python安装程序\python.exe C:/Users/欢/PycharmProjects/untitled/编程.py
good
100
good
100
good
100

Process finished with exit code 0
# encoding:utf-8
a = 100
def fun():
    if True:
        print "good"
print a

fun()
fun()
fun()
D:\Python安装程序\python.exe C:/Users/欢/PycharmProjects/untitled/编程.py
100
good
good
good

Process finished with exit code 0
形参和实参
#coding:utf-8                                     
def mashine(x,y='奶油'):                            
    print "制作一个",x,'元',y,'口味的冰淇淋!'                
                                                  
mashine( 3,'巧克力')                                 
                   
D:\Python安装程序\python.exe C:/Users/欢/PycharmProjects/untitled/编程.py
制作一个 3 元 巧克力 口味的冰淇淋!

Process finished with exit code 0
x和y要一一对应,若只输入y的值,mashine(y=‘奶油’)若只输入x的值,mashine(3)
输出一句话要用 "制作一个",x,'元',y,'口味的冰淇淋!'注意符号的使用
局部变量和全部变量                            
#coding:utf-8
a= 'i am global var'/*全部变量*/
def fun():
    a=100/*局部变量,不可以被当作全部变量使用*/
    global x/*局部变量,只要函数fun()被调用,x就可以当全部变量来使用*/
    x=200
    print a
fun()
print x

D:\Python安装程序\python.exe C:/Users/欢/PycharmProjects/untitled/ll.py
100
200

Process finished with exit code 0