Python 多参数的赋值(Tuple/List/Dict)

1、向函数传递Tuple数据类型对象

#!/usr/bin/env pthon
#conding=utf8
def printYourEnter(input1,input2):
    """Document:just"""
    print input1
    print input2
    for var in input2:
        print var
if __name__ == '__main__':
    enter1 = raw_input("Pls enter your living city:")
    enter2 = raw_input("Pls enter your name:")
    enter3 = raw_input("Pls enter you age:")
    tuple1 = (enter2,enter3)
    printYourEnter(enter1,tuple1)

2、向函数传递List类型对象

#!/usr/bin/env python
def printYourEnter(input1,x,y):
    print input1
    print x
    print y
if __name__ == '__main__':
    enter1 = raw_input("Pls enter your living city:")
    enter2 = raw_input("Pls enter name:")
    enter3 = raw_input("Pls enter your age:")
    li1 = [enter2,enter3]
    printYourEnter(enter1,*li1)

注意:

上面两个例子是两种不同的表现形式,其实这两种形式Tuple、List都可以使用。

3、向函数传递Dictionary类型对象

#!/usr/bin/enb python
"""Documen:Just Dict value"""
def printYouEnter(input1,city,name,age):
    print input1
    print city
    print name
    print age
if __name__ == '__main__':
    enter1 = raw_input("Pls enter city:")
    enter2 = raw_input("Pls enter name:")
    enter3 = raw_input("Pls enter age:")
    dic = {'city':enter1,'name':enter2,'age':enter3}
    printYouEnter('a',**dic)

 

你可能感兴趣的:(Python脚本)