keke-xiaoxiami

【Python基础教程第2版】——第一讲:基础知识

1、长字符串:(用三引号如\'\'\'或者"""来引起来)

>>> print """
This is a very log string.
It continues here.
And it\'s not over yet.
"Hello world!"
"""

This is a very log string.
It continues here.
And it\'s not over yet.
"Hello world!"

 

2、原始字符串:(注:最后面不要出现转义符,其他的都会保持原样显示,中间不用使用转义符)

>>> print r\'C:\nowhere\'
C:\nowhere

 

3、字符串表示:str和repr

(str函数:会把值转换为合理形式的字符串;repr函数:会创建一个字符换,以合法的Python表达式的形式来表示值)

>>> print str(temp)
42
>>> print \'1238934\'+str(temp)
123893442

>>> print \'the temp is \'+ repr(temp)
the temp is 42

 

分类:

技术点:

相关文章: