Chapter3.1 Python函数(1)

来源:互联网 发布:诺基亚500软件 编辑:程序博客网 时间:2024/06/05 07:07

#Python函数

#!/usr/bin/env python# -*- coding:utf-8 -*-#Author:xp#blog_url: http://blog.csdn.net/wuxingpu5/article/details/71209731#Python函数'''定义函数调用函数函数返回值函数参数函数对象函数嵌套名称空间与作用域闭包迭代器''''''内置函数自定义函数无参函数有参函数空函数'''## 语法# def 函数名(参数1,参数2,...):#     '''文档注释'''#      函数体#      return 值#内置函数# sum()# max()# min()# len()# a = len('hello')# print(a)# b = max(1,2,3)# b = max ([1,2,3])# print(b)#自定义函数# def print_msg():#     print('Hello world')# print_msg()#注: 函数需要先定义再使用#==================================================================================================#无参函数#如果函数的功能只是执行一些操作而已,就定义成无参函数#def print_star():#    print('#'*6)#有参函数  通常有返回值# x = 10# y = 2# if x > y:#     print(x)# else:#     print(y)#三元表达式  条件成立的情况下返回左侧的值#res = x if x > y else y#print(res)# def my_max(x,y):#     res = x if x > y else y#     return res## print(my_max(x,y))#空函数# def auth():#     '''认证功能'''#     pass# auth()