SICP-2.2-String

字符串


  • Python中文本值叫做string,构造函数为str
  • 形式为内容被单引号或双引号包含
    • 多行文本值为三引号包含文本内容
>>> 'I am string!'
'I am string!'
>>> "I've got an apostrophe"
"I've got an apostrophe"
>>> '您好'
'您好'

>>> """The Zen of Python
claims, Readability counts.
Read more: import this."""
'The Zen of Python\nclaims, "Readability counts."\nRead more: import this.'
  • string符合前面提到的序列的两个特性
    • 它有长度
    • 它有元素选择器
  • 和序列相同,Python支持操作符操作
  • 字符串构造器——str()
>>> str(2) + ' is an element of ' + str(digits)
'2 is an element of [1, 8, 2, 8]'

猜你喜欢

转载自blog.csdn.net/a245293206/article/details/73742359
2.2