最后得到数值的:
算数运算符
赋值运算符
最后得到布尔值的:
成员运算符:in not in
逻辑运算符 and or 没有优先级就是按顺序执行
比较运算符
1、整型 int
2、字符型str
3、列表list
4、元组tuple
5、字典dirt
6、布尔bool
pycharm 中ctrl + 鼠标左键 可以跳转
int(‘123‘) #类型转换
a = 123
v = a.bit_length() #计算出整型变量 占了几位 bit
text = ‘alex‘ v = text.capitalize() #首字母大写 print(v)
text.casefold() 这个是特殊语言的转换 一般还是使用lower() 来字母小写
text.upper() 字母大写
test = ‘alex‘ v1 = test.center(20,‘$‘) #字符串居中,后面接宽度,用单个字符填充 print(v1)
test = ‘alex‘ v = test.count(‘a‘,0,10) #计算字符串出现的次数,可选起止位 print(v)
endswith startswith 判断是否以字符串开头或者结尾,返回True Flase
test = ‘alex‘ v = test.find(‘w‘) #查找字符串,返回所在位置,第几位bit, 如果不存在返回 -1 ,index也可以查找,但是找不到就报错,所以以后都用find print(v)
a = ‘his name is {name} , age is {age}‘ #可以加参数 ,赋值 v = a.format(name = ‘alex‘,age = 19) print(v) a = ‘his name is {} , age is {}‘ # 可以加编号,赋值 v = a.format(‘alex‘,19) print(v)
a = ‘his name is {name} , age is {age}‘ v = a.format_map({"name":‘alex‘,"age":19}) #可以用字典直接赋值 print(v)
a = ‘alex‘ v = a.isalnum() #是否全是字母或者数字 返回布尔值 print(v)
原文:https://www.cnblogs.com/dayouge/p/10797203.html