python内置函数字符串
一、字符串定义初始化 s1 = 'string' 一个个字符组成的有序的序列,是字符的集合,使用单引号,双引号,三引号引住的字符序列 字符串是不可变的对象,python3起,字符串就是Unicode类型 二、字符串元素访问 1、 字符串支持使用索引访问 sql = "select * from user where name='tom'" sql[4] 字符串访问 sql[4] = 'o' 字符串赋值能否成功? (不能赋值) >>> sql = "select * from user where name='tom'" >>> sql "select * from user where name='tom'" >>> sql[4] 'c' >>> sql[4] = 'o' Traceback (most recent call last): File "<pyshell#52>", line 1, in <module> sql[4] = 'o' TypeError: 'str' object does not support item assignment >>> 2、有序的字符集合,字符序列可迭代 >>> for x in sql: print(x) 三、字符串join连接 将可迭代对象连接起来,使用string作为分隔符 可迭代对象本身元素都是字符串,返回一个新字符串