1、SyntaxError:EOL while scanning string literal
语法错误:扫读字符串文本时遇到EOL行结尾
【注意】在字符串中使用多余一行的文字(多行字符串)时,得使用三个单引号,然后在行之间输入回车,像这样:
>>>fred='''luhan,luhan
fighting!'''
2、转义(\):字符串中间的每个引号前加一个反斜杠。
>>> string='He said,"Aren\'t can\'t shouldn\'t wouldn\'t."'
>>> print(string)
He said,"Aren't can't shouldn't wouldn't."
3、在字符串里嵌入值:
myscore=100
>>> message='I scored %s points!'
>>> print(message % myscore)
I scored 100 points!
(1) 对于同一个%s占位符可以用不同的变量来传给它不同的值。
(2)一个字符串也可使用多个占位符。
>>> nums='This is the number %s and %s !'
>>> print(nums %(0,7))
This is the number 0 and 7 !
4、想要注释中文必须先加上#-*-coding:utf-8-*
批量多行注释
" " "
print r '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
" " "