[python]中的* 和**

2019-04-28  本文已影响0人  VanJordan
def adder(*num):
    sum = 0
    
    for n in num:
        sum = sum + n

    print("Sum:",sum)

adder(3,5)
adder(4,5,6,7)
adder(1,2,3,5,6)
def intro(**data):
    print("\nData type of argument:",type(data))

    for key, value in data.items():
        print("{} is {}".format(key,value))

intro(Firstname="Sita", Lastname="Sharma", Age=22, Phone=1234567890)
intro(Firstname="John", Lastname="Wood", Email="johnwood@nomail.com", Country="Wakanda", Age=25, Phone=9876543210)
a = [1,2,3,4]
print(*a)
>>> 1 2 3 4
a = [1,2,3,4]
b = [5,6,7,8]

print(*zip(a,b))
>>> (1, 5) (2, 6) (3, 7) (4, 8)
a = [1,2,3,4]
b = [5,6,7,8]

d,f,g,h = zip(a,b)
print(d)
>>> (1, 5)
上一篇下一篇

猜你喜欢

热点阅读