1 # this one is like your scripts with argv 2 def print_two(*args): #函数命名规则和变量名一样,只能以字母、数字和下划线组成,数字不可以作为开头 3 arg1, arg2 = args 4 print ("arg1: %r, arg2: %r" % (arg1,arg2)) # 不要混淆TAB键和空格键,这里要用到4个空格 5 6 # ok ,that *args is actually pointless,we can just do this 7 def print_two_again(arv1,arv2): 8 print ("arv1: %r, arv2: %r" % (arv1,arv2)) #变量参数要和定义函数内的参数相一致 9 10 # this just takes one argument 11 def print_one(arg1): #不要遗忘冒号 12 print("arg1: %r" % arg1) 13 14 #this one takes no argument 15 def print_none(): 16 print ("I got nothin") 17 18 print_two("ZED","Shaw") 19 print_two_again("ZED","Shaw") 20 print_one("First!") 21 print_none() 22 23 24
时间: 2024-10-14 00:43:50