最新资讯
咸阳IATF16949汽车行业质量管理体系认证具体内容,为企业赋能
ERROR
%s''' cursor.execute(''' CREATE TABLE users ( login VARCHAR(8), uid INTEGER, prid INTEGER) ''') ``` ## Unicode 字符串 Python 中定义一个 Unicode 字符串和定义一个普通字符串一样简单: ```python >>> u'Hello World !' u'Hello World !' ``` 引号前小写的 "u" 表示这里创建的是一个 Unicode 字符串。你想加入一个特殊字符,使用 Python 的 Unicode-Escape 编码。如下例所示: ```python >>> u'Hello\u0020World !' u'Hello World !' ``` 被替换的 \u0020 标识表示给定位置插入编码值为 0x0020 的 Unicode 字符(空格符)。 ## python 的字符串内建函数 字符串方法是从 python1.6 到 2.0 慢慢加进来的——它们也被加到了 Jython 中。 这些方法实现了 string 模块的大部分方法,如下表所示列出了目前字符串内建支持的方法,所有的方法都包含了对 Unicode 的支持,有一些甚至是专门用于 Unicode 的。 | 方法 | 描述 | | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [capitalize()](https://www.runoob.com/python/att-string-capitalize.html) | 将字符串的第一个字符转换为大写 | | [center(width, fillchar)](https://www.runoob.com/python/att-string-center.html) | 返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格。 | | [count(str, beg= 0,end=len(string))](https://www.runoob.com/python/att-string-count.html) | 返回 str string 里面出现的次数, beg 或者 end 指定则返回指定范围内 str 出现的次数 | | [bytes.decode(encoding="utf-8", errors="strict")](https://www.runoob.com/python/att-string-decode.html) | Python3 中没有 decode 方法,但我们使用 bytes 对象的 decode() 方法来解码给定的 bytes 对象,这个 bytes 对象由 str.encode() 来编码返回。 | | [encode(encoding='UTF-8',errors='strict')](https://www.runoob.com/python/att-string-encode.html) | 以 encoding 指定的编码格式编码字符串,出错默认报一个ValueError 的异常,除非 errors 指定的是'ignore'或者'replace' | | [endswith(suffix, beg=0, end=len(string))](https://www.runoob.com/python/att-string-endswith.html) | 检查字符串是否以 obj 结束,beg 或者 end 指定则检查指定的范围内是否以 obj 结束,是,返回 True,不然会返回 False. | | [expandtabs(tabsize=8)](https://www.runoob.com/python/att-string-expandtabs.html) | 把字符串 string 中的 tab 符号转为空格,tab 符号默认的空格数是 8 。 | | [find(str, beg=0, end=len(string))](https://www.runoob.com/python/att-string-find.html) | 检测 str 是否包含字符串中,指定范围 beg 和 end ,则检查是否包含指定范围内,包含返回开始的索引值,不然会返回-1 | | [index(str, beg=0, end=len(string))](https://www.runoob.com/python/att-string-index.html) | 跟find()方法一样,只不过str不字符串中会报一个异常。 | | [isalnum()](https://www.runoob.com/python/att-string-isalnum.html) | 字符串至少有一个字符并且所有字符都是字母或数字则返 回 True,不然会返回 False | | [isalpha()](https://www.runoob.com/python/att-string-isalpha.html) | 字符串至少有一个字符并且所有字符都是字母则返回 True, 不然会返回 False | | [isdigit()](https://www.runoob.com/python/att-string-isdigit.html) | 字符串只包含数字则返回 True 不然会返回 False.. | | [islower()](https://www.runoob.com/python/att-string-islower.html) | 字符串中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是小写,则返回 True,不然会返回 False | | [isnumeric()](https://www.runoob.com/python/att-string-isnumeric.html) | 字符串中只包含数字字符,则返回 True,不然会返回 False | | [isspace()](https://www.runoob.com/python/att-string-isspace.html) | 字符串中只包含空白,则返回 True,不然会返回 False. | | [istitle()](https://www.runoob.com/python/att-string-istitle.html) | 字符串是标题化的(见 title())则返回 True,不然会返回 False | | [isupper()](https://www.runoob.com/python/att-string-isupper.html) | 字符串中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是大写,则返回 True,不然会返回 False | | [join(seq)](https://www.runoob.com/python/att-string-join.html) | 以指定字符串作为分隔符,将 seq 中所有的元素(的字符串表示)合并为一个新的字符串 | | [len(string)](https://www.runoob.com/python/att-string-len.html) | 返回字符串长度 | | [ljust(width[, fillchar])](https://www.runoob.com/python/att-string-ljust.html) | 返回一个原字符串左对齐,并使用 fillchar 填充至长度 width 的新字符串,fillchar 默认为空格。 | | [lower()](https://www.runoob.com/python/att-string-lower.html) | 转换字符串中所有大写字符为小写. | | [lstrip()](https://www.runoob.com/python/att-string-lstrip.html) | 截掉字符串左边的空格或指定字符。 | | [maketrans()](https://www.runoob.com/python/att-string-maketrans.html) | 创建字符映射的转换表,接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标。 | | [max(str)](https://www.runoob.com/python/att-string-max.html) | 返回字符串 str 中最大的字母。 | | [min(str)](https://www.runoob.com/python/att-string-min.html) | 返回字符串 str 中最小的字母。 | | [replace(old, new [, max])](https://www.runoob.com/python/att-string-replace.html) | 把 将字符串中的 str1 替换成 str2, max 指定,则替换不超过 max 次。 | | [rfind(str, beg=0,end=len(string))](https://www.runoob.com/python/att-string-rfind.html) | 类似于 find()函数,不过是从右边开始查找. | | [rindex( str, beg=0, end=len(string))](https://www.runoob.com/python/att-string-rindex.html) | 类似于 index(),不过是从右边开始. | | [rjust(width,[, fillchar])](https://www.runoob.com/python/att-string-rjust.html) | 返回一个原字符串右对齐,并使用fillchar(默认空格)填充至长度 width 的新字符串 | | [rstrip()](https://www.runoob.com/python/att-string-rstrip.html) | 删除字符串字符串末尾的空格. | | [split(str="", num=string.count(str))](https://www.runoob.com/python/att-string-split.html) | 以 str 为分隔符截取字符串, num 有指定值,则仅截取 num 个子字符串 | | [splitlines([keepends])](https://www.runoob.com/python/att-string-splitlines.html) | 按照行('\r', '\r\n', \n')分隔,返回一个包含各行作为元素的列表,参数 keepends 为 False,不包含换行符,为 True,则保留换行符。 | | [startswith(substr, beg=0,end=len(string))](https://www.runoob.com/python/att-string-startswith.html) | 检查字符串是否是以指定子字符串 substr 开头,是则返回 True,不然会返回 False。beg 和 end 指定值,则指定范围内检查。 | | [strip([chars])](https://www.runoob.com/python/att-string-strip.html) | 字符串上执行 lstrip()和 rstrip() | | [swapcase()](https://www.runoob.com/python/att-string-swapcase.html) | 将字符串中大写转换为小写,小写转换为大写 | | [title()](https://www.runoob.com/python/att-string-title.html) | 返回"标题化"的字符串,就是说所有单词都是以大写开始,其余字母均为小写(见 istitle()) | | [translate(table, deletechars="")](https://www.runoob.com/python/att-string-translate.html) | 根据 str 给出的表(包含 256 个字符)转换 string 的字符, 要过滤掉的字符放到 deletechars 参数中 | | [upper()](https://www.runoob.com/python/att-string-upper.html) | 转换字符串中的小写字母为大写 | | [zfill (width)](https://www.runoob.com/python/att-string-zfill.html) | 返回长度为 width 的字符串,原字符串右对齐,前面填充0 | | [isdecimal()](https://www.runoob.com/python/att-string-isdecimal.html) | 检查字符串是否只包含十进制字符,是返回 true,不然会返回 false。 |

