码迷,mamicode.com
首页 > 编程语言 > 详细

Python 函数

时间:2018-06-26 10:52:11      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:add   文件   pytho   and   参数   coding   comm   ret   函数名   

#-*- coding:utf-8 -*-

‘‘‘

def 函数名(参数列表):
[tab键] command
[tab键] command
...


‘‘‘


def showHello():
        print("hello world .")

#定义带参数的函数
def add(num1,num2):
        print("%d+%d=%d"%(num1,num2,num1+num2))

#定义带返回值的函数
def mult(num1,num2):
        return num1*num2

#函数中多个值的返回
def return_more():
        a = 11
        b = 22
        c = 33
        #return [a,b,c] #做一个列表返回
        #return (a,b,c) #做一个元组返回
        return a,b,c   #这也是做一个元组返回

#函数的调用
showHello()

add(2,3)

print(mult(3,5))

nums = return_more()

for tmp in nums:
        print(tmp)

 

同一文件中,python的函数名不能使用相同的函数名

Python 函数

标签:add   文件   pytho   and   参数   coding   comm   ret   函数名   

原文地址:https://www.cnblogs.com/zhanggaofeng/p/9227196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!