python day02 用户交互

python day02 用户交互

引号 & 注释
单引号、双引号的区别和shell一样
单行注释:#,多行‘’‘ 要注释的内存 ’‘’



自动补全
    
  1. import sys
  2. import readline
  3. import rlcompleter
  4. import atexit
  5. import os
  6. readline.parse_and_bind('tab: complete')
  7. histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
  8. try:
  9. readline.read_history_file(histfile)
  10. except IOError:
  11. pass
  12. atexit.register(readline.write_history_file,histfile)

导入模块
        import os    #导入os下所有
        from os import system #导入 os 下System
        import SocketServer as SS #导入并取别名


用户交互
    
    命令行版本:
  1. >>> raw_input('please input your name:')
  2. please input your name:bill
  3. 'bill'
  4. >>> name = raw_input('please input your name:')
  5. please input your name:bill
  6. >>> name
  7. 'bill'
  8. >>>
 脚本版本:
  1. #!/usr/bin/env python
  2. this_year = 2015
  3. name = raw_input("please input your name:")
  4. age = int(raw_input("how old are you:"))
  5. sex = raw_input("please input your sex:")
  6. dep = raw_input("which department:")
  7. message = '''Infomation of the company staff:
  8. Name: %s
  9. Age : %d
  10. Sex : %s
  11. Dep : %s
  12. ''' % (name,age,sex,dep)
  13. print "hello",name,"\n"
  14. print "you are",age,"years old!"
  15. print "so you were born in: ",this_year - age
  16. print "--------------- format ---------------"
  17. print message
    

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注