python字符串操作大全

    技术2022-07-11  84

    关键字:解释器用关键字识别程序的结构。 同关键词。 共33个关键词。 值类: False 错,0 True 对,1 None 无 判断类: and 与 or 或 not 非 is 是,== in 在 assert 声称

    函数类: class 类定义 def 定义函数 nonlocal 访问全局变量(无修改权限) global 引入全局变量或创建全局变量(全权) del 删除变量-释放相应内存 return 函数结束,返回值 yield 函数继续,返回值 lambda 匿名函数 from、import 引入包

    结构类 as 以某种简写表示,用于with、import结构 break 当前循环终止,与if,while,for结构 if 条件 elif 另条件,必须在if后 else 其他,必须在if,try,for,内 try,except,raise 错误引发系统 pass,continue,继续

    语句:会产生影响的代码单元。没有值。

    字符串操作大全: https://www.w3school.com.cn/python/python_ref_string.asp in 判断’有’ is 判断’是’ +拼接 *重复

    He='李佳琦' if He is '李佳琦' and 'money' in 'my money pocket': print"'还等什么呢?'+'买它!'*3" print('还等什么呢?'+'买它!'*3)

    大小写相关 所有字符串方法都返回新值。它们不会更改原始字符串。

    A='bob have an iPhone. as a result, he has no kidneys.' print(A.lower()) print(A.upper()) print(A.title()) print(A.islower()) print(A.isupper()) print(A.istitle()) print(A.capitalize()) print(A.swapcase())

    数字及字符相关

    A='陪聊服务请拨打82668110.' print(A.lower()) print(A.upper()) print(A.title()) print(A.islower()) print(A.isupper()) print(A.istitle()) print(A.capitalize()) print(A.swapcase())

    查找替换删除相关

    find/rfind/index 从左右左寻找对象,若找到则返回索引,否则返回-1 -1 error

    center/ljust/rjust(str,num) 使A在num个字符中居中/左对齐/右对齐 strip/lstrip/lstrip 从全方向/左/右删除A里面的str zfill 用“0”填充至num个字符

    count 数A里面str的个数,从start数到end partition 用str分段,并把所有段保存成元组返回至A split/replit 用str分段,并把去掉str后的其他段保存成元组返回至A splitlines 用\n分段,并把去掉str后的其他段保存成元组返回至A replace 在A中用str2替换str1

    maketrans/translate 用str1、str2一一对应的方式,把A中含有的str1字符转换成str2 expandtabs 将\t替换为指定空格数 find/rfind/index 左右/右左/左右方向寻找,返回第一找到位置的索引,若未找到则返回-1/-1/errpr join 将A插进str里面 encode/decode 字符与UTF-8之间的转换 format 用str表示的字符集合,对应n个str,组成长句

    isspace isprintable isnumeric isdigit isidentifier isdecimal isalpha isalnum startwith endswith -不常用casefold -非ASCII码范围内的小写

    Processed: 0.012, SQL: 9