SICP-2.2-String

来源:互联网 发布:vc 多线程编程 编辑:程序博客网 时间:2024/06/03 09:08

字符串


  • Python中文本值叫做string,构造函数为str
  • 形式为内容被单引号或双引号包含
    • 多行文本值为三引号包含文本内容
>>> 'I am string!''I am string!'>>> "I've got an apostrophe""I've got an apostrophe">>> '您好''您好'>>> """The Zen of Pythonclaims, 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]'
原创粉丝点击