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

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

时间:2020-07-18 13:33:56      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:学python   zed   接收   参数   意思   his   fir   this   code   

 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()

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

标签:学python   zed   接收   参数   意思   his   fir   this   code   

原文地址:https://www.cnblogs.com/lsc666js/p/13334702.html

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