
字符串
Misty_yezi
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
字符串方法find/rfind/rindex/index/count/replace
用dir(str)可以查询字符串的所有方法 1.find 语法:str.find(sub, [start,end) ) \\\\\根据指定的数据查找对应的索引 解释:在字符串中查找子串,如果找到,返回子串的第一个字符的index,否则返回 -1。 note1:可以指定搜索的范围,[start,end),find方法返回的不是布尔值,找到返回index,找不到返回-1。 note...原创 2019-10-09 18:30:41 · 800 阅读 · 1 评论 -
字符串方法split/rsplit/splitlines/lower/upper/title/startswith/endswith
5.split 语法:str.split(sep=None,maxsplit = -1) 或str.split(sep=None,maxsplit = -1)[n] 解释:拆分str,通过指定的sep对str进行分割,并返回分割后的字符串列表 sep为分隔符,默认为所有空字符,包括空格(‘ ’),换行(\n),制表符(\t),但不可为空,若字符串中没有...原创 2019-10-09 19:48:31 · 347 阅读 · 0 评论 -
字符串方法center/rjust/ljust/zfill/strip/rstrip/lstrip
12:center 语法:str.center(width,[fillchar]) 解释:返回一个长度为width,两边用fillchar填充的字符串,默认为空格填充;若width小于len(str),则返回原字符串。 >>> x = 'apple' >>> x.center(9) ' apple ' >>> x.center(9,'*...原创 2019-10-10 10:48:16 · 317 阅读 · 0 评论 -
字符串方法partition/rpartition/join
19.partition 语法:str.partition(sep) \\\\\把字符串以指定字符分割 解释:在字符串中搜索sep,并返回元组(sep前面的部分,sep,sep后面的部分) >>> x = 'apple' >>> x.partition('pl') ('ap', 'pl', 'e') 19.2 rpartition 语法:str.re...原创 2019-10-10 12:17:29 · 399 阅读 · 0 评论 -
字符串
字符串:是由数字,字母,下划线组成的的一串字符 定义字符串:使用单引号,双引号,三引号,’‘ , ” ”,“”“ ”“”。 note:区分三引号字符串(变量和赋值符号)和注释 ...原创 2019-10-10 20:50:50 · 136 阅读 · 0 评论