123456789101112131415 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- def hello(greeting, *args):
- if (len(args)==0):
- print('%s!' % greeting)
- else:
- print('%s, %s!' % (greeting, ', '.join(args)))
- hello('Hi') # => greeting='Hi', args=()
- hello('Hi', 'Sarah') # => greeting='Hi', args=('Sarah')
- hello('Hello', 'Michael', 'Bob', 'Adam') # => greeting='Hello', args=('Michael', 'Bob', 'Adam')
- names = ('Bart', 'Lisa')
- hello('Hello', *names) # => greeting='Hello', args=('Bart', 'Lisa')
|