python day02 用户交互
引号 & 注释
单引号、双引号的区别和shell一样单行注释:#,多行‘’‘ 要注释的内存 ’‘’
自动补全
import sys
import readline
import rlcompleter
import atexit
import os
readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.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 python
this_year = 2015
name = 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: %s
Age : %d
Sex : %s
Dep : %s
''' % (name,age,sex,dep)
print "hello",name,"\n"
print "you are",age,"years old!"
print "so you were born in: ",this_year - age
print "--------------- format ---------------"
print message