Discuss / Python / 关于参考源码的问题

关于参考源码的问题

Topic source

宫长小生

#1 Created at ... [Delete] [Delete and Lock User]

问题一: 那个var_args.py中

def hello(greeting, *args):
    if (len(args)==0):
        print('%s!' % greeting)
    else:
        print('%s, %s!' % (greeting, ', '.join(args)))

print里这个.jion是什么作用?

问题二:

那个kw_agrs.py中

def print_scores(**kw):
    print('      Name  Score')
    print('------------------')
    for name, score in kw.items():
        print('%10s  %d' % (name, score))
    print()

for循环里那个kw.items()是什么意思?

明仔君

#2 Created at ... [Delete] [Delete and Lock User]

1) ', '.join(args)---> 用逗號把args的各個值鏈接成一個string 2) kw.items() --> 迭代拿出kw 的所有值

廖雪峰

#3 Created at ... [Delete] [Delete and Lock User]

自己多在Python交互环境下做试验:

>>> ', '.join(['a', 'b', 'c'])
'a, b, c'

  • 1

Reply