第18个python程序:命名变量代码函数

来源:互联网 发布:淘宝客服销售技巧 编辑:程序博客网 时间:2024/05/22 13:39
[root@mysql1 pshell]# cat ex18.py 
#!/usr/bin/env Python
#-*-coding:utf-8-*-


# this one is like your scripts with argv
def print_two(*args):
   arg1,arg2=args
   print "arg1: %r,arg2: %r" % (arg1,arg2)


#ok,that *args is actually pointless,we can just do this
def print_two_again(arg1,arg2):
   print "arg1: %r,arg2: %r" % (arg1,arg2)


#this just takes one argument
def print_one(arg1):
   print "arg1: %r" % arg1


# this one takes no arguments
def print_none():
   print "i got nothin'."


print_two("zed","shaw")
print_two_again("zed","shaw")
print_one("first!")
print_none()
[root@mysql1 pshell]# 
[root@mysql1 pshell]# 
[root@mysql1 pshell]# 
[root@mysql1 pshell]# python ex18.py 
arg1: 'zed',arg2: 'shaw'
arg1: 'zed',arg2: 'shaw'
arg1: 'first!'
i got nothin'.
0 0