魔法和运算器

运算器

2018-12-11 00:45:43

24

1.+ - * /除 **幂 %取余数 / /取整数

2.判断一个值或东西是否在另一个整体里

if ,,, not in ,,, if,,,in,,,

例: 例:

a=(“b” “c”) a=(“b” “c”)

if“b”not in a if“b”in a

print(1) print(2)

else else

print(2) print(1)

三、魔法

1.test.copitalize( )首字母大写

2.test.casefold( )

test.lower( ) 大写变小写

test.swapcase( )小写变大写

test.upperl( )

3.test.center( ) 表示宽度,居中

test.l just( ) 居左

test.r just( ) 居右

4.test.strip( ) 两边

test.lstrip( )左

test.rstrip( )右 除去左两边空白,/n,/t,也可以指定字符

5.test.count( ) 去字符串找子序列的次数

test.find( ) 去字符串中找子序列的位置,也可以设置范围

test.index( ) 根据值获得位置

6.test.endswith( ) 以……结尾

test.startswith( ) 以……开始

7.test.format( 字符串占位符=“子序列” ) 格式化 ,将字符串占位符代替子序列

test.format-map({ :“ ”}) 字典形式

8.str.maketrans( )

test.translate( )合用 代替 替换

9.test.replace( )老字符列代替新字符列

10.test.expocndtabs( ) 对字符串进行截断

/t 制表符 /n换行符

11.test.isalnum( )判断字符串是否存在字母和数字

test.isalpha( )判断字符串是否存在字母和汉子

12.test.isdecimal( )判断字符串是否有数字

test.isdigit( ) 支持序号1等

test.isnumeric( ) 支持大写数字

13.test.islower( )判断字符串是否小写

14.test.isprintable( )判断字符串是否存在不可见的字符,没有就可以打印

15.test.isspace( )判断字符串是否都是空格,也就是空字符

16.test.istitle( )判断是否标题

17.test.title( )把字符串转换成标题

18.test.join( )把什么插入字符串 如:v=“a ”.join( )

li.inse(位置,值)可以选位置插入

19.test.partition( )以第一个参数分割

test.rpartition( )以第二个参数分割

test.split( )以每个参数分割,不包括参数

test.isplit( )判断是否以每个参数分割

test.splitlines( )分割,只能根据/n换行,true.false是否存在换行符

20.len字符串有多少字符

for循环格式

for 变量名 in 字符串

print(变量名)

索引:是指字符串第几位是什么

切片:字符串中的一段

如 test([0:1])

21.字符串一旦创建就不能修改

一旦修改或拼接,就会重新生成字符串

22.break结束

contincle 循环当前

input 等待用户输入

23.li.extend( )在原来里加,也可以合并

li.append( )在原来里加

24.li.clear( )清空

25.li.copy( )浅拷贝,相当于复制

26.li.tuple( )转换列表,元祖,字符之间

27.li.pop( )默认删除尾数并可获得删除值

li.remove( )删除指定

der删除

28.li.reverse( )将当前位置反转

29.li,sort( )排序

猜你喜欢

转载自www.cnblogs.com/cui00/p/11432796.html