笨办法学python3练习代码ex18.py

时间:2020-07-18 13:33:56   收藏:0   阅读:109
 1 #命名、变量、代码、函数
 2 #this one is like your scripts with argv
 3 def print_two(*args):
 4     arg1, arg2 = args                       #将参数解包
 5     print(f"arg1: {arg1}, arg2: {arg2}")
 6 ‘‘‘
 7 (*args) 里面*的意思:告诉Python把所有的参数都接收进来,放到名叫args的列表中去
 8 ‘‘‘ 
 9  
10 #ok,that‘s *agrs is actually pointless(无意义的),we can just do this
11 def print_two_again(arg1, arg2):
12     print(f"arg1: {arg1}, arg2: {arg2}")
13     
14 #this just takes one argument
15 def print_one(arg1):
16     print(f"arg1: {arg1}")
17     
18     
19 #this one takes no arguments
20 def print_none():
21     print("I got nothin‘.")
22     
23     
24 print_two("Zed","Shaw")     #不带引号会出错,但是数字可以不带引号
25 print_two_again("Zed","Shaw")
26 print_one("First!")
27 print_none()
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!