input与raw_input比较:
1.input函数:需要以合法的python表达式形式输入
如:
>>> name = input ("what is your name ?")
what is your name ?
当输入为数值型:3时,通过;当输入为字符型:lucy时,抱错:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
name = input ("what is your name ?")
File "<string>", line 1, in <module>
NameError: name 'lucy' is not defined
因为字符型的合法表达式应为:'lucy',如果输入'lucy'或者"lucy"则通过
2.raw_input函数:将会把所有的输入当原始数据处理
如:
>>> name = raw_input ("what is your name ?")
what is your name ?lucy
>>>
此时直接输入lucy就不会抱错。
capitalize()
capitalize()方法返回字符串的一个副本,只有它的第一个字母大写。对于8位的字符串,这个方法与语言环境相关。