1. 在python3.5中使用print,打印內容必須用括號()括起來。python2.7中可以不用括號,如果你加了括號,代碼在python2.7中也是可以正常運行的。
python3.5 examples:
print("this is the format in python3.5") version="python3.5" print("this is the format in",version) print("this is the format in %s" %version) language="python" version=3 print("this is the format in %s%d" % (language,version))
2. raw_input在python3.5中消失了,input方法取代了它。然而,如果你是在python2.7中使用input方法,其效果跟python3.5中完全不同。python2.7中的input方法,只能接受變量作為傳入值,否則會報錯,如下:
python2.7中使用input時的正確做法:(不看也罷,反正3.5開始就沒這回事了)
補充,在python3.5中格式化字符串。用三引號將排版好的字符串引起來即可,三引號可以是3個單引號,也可以是3個雙引號。
name =input("input your name:") age =input("input your age:") job =input("input your job:") msg = ''' Information of user %s: ------------------------- name:%s age:%d job:%s ------------End---------- ''' % (name,name,age,job) print(msg)