python day02 用户交互
引号 & 注释
单引号、双引号的区别和shell一样单行注释:#,多行‘’‘ 要注释的内存 ’‘’
自动补全
import sysimport readlineimport rlcompleterimport atexitimport osreadline.parse_and_bind('tab: complete')histfile = os.path.join(os.environ['HOME'],'.pythonhistory')try:readline.read_history_file(histfile)except IOError:passatexit.register(readline.write_history_file,histfile)
导入模块
import os #导入os下所有
from os import system #导入 os 下System
import SocketServer as SS #导入并取别名
用户交互
命令行版本:
>>> raw_input('please input your name:')please input your name:bill'bill'>>> name = raw_input('please input your name:')please input your name:bill>>> name'bill'>>>
脚本版本:
#!/usr/bin/env pythonthis_year = 2015name = raw_input("please input your name:")age = int(raw_input("how old are you:"))sex = raw_input("please input your sex:")dep = raw_input("which department:")message = '''Infomation of the company staff:Name: %sAge : %dSex : %sDep : %s''' % (name,age,sex,dep)print "hello",name,"\n"print "you are",age,"years old!"print "so you were born in: ",this_year - ageprint "--------------- format ---------------"print message