>>> name = raw_input("what's your name? ")
what's your name? world #把输入world作为原始数据放入字符串中
>>> print "Hello " + name
Hello world
>>> name = input("what's your name? ")
what's your name? world #world不是合法的python表达式
Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
name = input("what's your name? ")
File "<string>", line 1, in <module>
NameError: name 'world' is not defined
>>> name = input("what's your name? ")
what's your name? "world" #使用input时,这里需要输入字符串"world",才是合法的python表达式
>>> print "Hello " + name
Hello world
>>> input("Enter a number: ")
Enter a number: 3 #数字3是合法的python表达式,并显示python表达式数字3
3
>>> raw_input("Enter a number: ")
Enter a number: 3 #虽然输入的是数字,但是显示字符串,因为把输入3作为原始数据放入字符串中
'3'
8. 使用"\"来对换行进行转义
使用三个单引号或双引号来表示长字符串,中间可以使用单引号及双引号
>>> print "hello \
world"
hello world #实现跨行表达一行字符串
>>> print """This is a
very long
string.
"Hello World!"
over""" #三个双引号表达长字符串,包括换行
This is a
very long
string.
"Hello World!"
over
>>> print '''This also is a
very long
string.'''
This also is a
very long
string.