简单的函数(也叫方法)

1、脚本

def max(a,b,c):
x = a
if (a<b): x=b
if (b<c): x=c
print ("the max num is %d" %x)

def hello(list):
list.append([1,2,3,4])
print(list)
return

list = [10,11,12]
hello(list)

max(1,2,3)

2、执行结果

3、备注

(1)函数以def开头;

         函数名括号中,可以有参数,也可以没有参数;

         函数名后边加冒号

         函数内容需要注意前边有4个空格的缩进量

(2)Python中if条件后边加冒号:

(3)Python List append()方法

append() 方法用于在列表末尾添加新的对象
append()方法语法:list.append(obj);obj为添加到列表末尾的对象。该方法无返回值,但是会修改原来的列表
如:脚本中,将[1,2,3,4]添加到[10,11,12]后边

(4)函数的引用

1个类中,函数可以随便引用

posted @ 2018-02-24 11:20  Tang豆豆  阅读(276)  评论(0编辑  收藏  举报