-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpython_var_args.py
More file actions
executable file
·51 lines (42 loc) · 1.01 KB
/
Copy pathpython_var_args.py
File metadata and controls
executable file
·51 lines (42 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'MFC'
__time__ = '2019-08-22 14:35'
# What's args?
def print_multiple_args(*args):
print(type(args), args)
for idx, val in enumerate(args):
print(idx, val)
print_multiple_args()
print("-"*40)
print_multiple_args("a")
print("-"*40)
print_multiple_args("a", "b")
print("-"*40)
print_multiple_args("a", "b", "c")
print("~"*40)
print_multiple_args(*["a", "b", "c"]) # 传入一个列表
print("*"*60)
# What's kwargs?
def print_kwargs(**kwargs):
print(type(kwargs), kwargs)
for k,v in kwargs.items():
print(f'{k}:{v}')
print_kwargs()
print("-"*40)
print_kwargs(a=1)
print("-"*40)
print_kwargs(a=1, b=2)
print("~"*40)
print_kwargs(**dict(a=1, b=2)) # 传入一个字典
print("*"*60)
# print all
def print_all(a, *args, **kwargs):
print(a)
if args:
print(f'args: {args}')
if kwargs:
print(f'kwargs: {kwargs}')
print_all('I', 'love' , name='python')
print("-"*40)
print_all('I', 'love', 'code' , name='python')