kw_args.py 739 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. def print_scores(**kw):
  4. print(' Name Score')
  5. print('------------------')
  6. for name, score in kw.items():
  7. print('%10s %d' % (name, score))
  8. print()
  9. print_scores(Adam=99, Lisa=88, Bart=77)
  10. data = {
  11. 'Adam Lee': 99,
  12. 'Lisa S': 88,
  13. 'F.Bart': 77
  14. }
  15. print_scores(**data)
  16. def print_info(name, *, gender, city='Beijing', age):
  17. print('Personal Info')
  18. print('---------------')
  19. print(' Name: %s' % name)
  20. print(' Gender: %s' % gender)
  21. print(' City: %s' % city)
  22. print(' Age: %s' % age)
  23. print()
  24. print_info('Bob', gender='male', age=20)
  25. print_info('Lisa', gender='female', city='Shanghai', age=18)
  26. print_info("1","1",1,"d",12);