A digital type built-in method
1.1 Integer built-in method
-
effect
Description age, number, id number
- Defined way
x = 10
x = int('10')
x = int(10.1)
x = int('10.1') # 报错
-
Built-in method
No built-in method, only the arithmetic and compare operations
-
A value or presence of a plurality of values
Save a value
-
Orderly or disorderly orderly: the index; disorder: None Index
Are they not say that
-
Variable or non-variable (Key)
Digital type immutable
- Variable (variable value terms)
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
lis = [1,2,3]
print(id(lis))
lis[0] = 2 #lis-->[2,2,3]
print(id(lis))
- Immutable (in terms of the value of the variable), the value becomes variable id
x = 10
print(id(x))
x = 20
print(id(x))
1.2 float built-in method
With integer
Second, the method of the built-in string type
2.1 Role
Name / gender / address
2.2 define how
s = b‘sdkfljl’ # 打印出来的bytes类型,二进制类型,010011001011001011
print(s)
print(‘中文’,encode(‘utf8’))
2.3 String built-in method (only string type to use)
s = ‘forever handsome’
Priority master (you must have to master today)
- Index values
print(s[1])
- Index sliced
print(s[4:0:1]) # 1 表示从左到右
print(s[-4:0:-1]) # -1 表示从右到左
- for loop
for i in s:
print(i)
- strip () specified character ends removed
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
s1 = ‘ nick handsome ’
print(s1.strip()) # 去除两端的空白
s2 = '****!!!nick handsome-----***'
print(s2.strip('-*!')) # 指定多个字符一起去掉,只能strip里面有的字符就全部干掉
- split () Cutting
print(s.split()) # 默认以空格为切割条件
print(s.split('/')) # 以/切割
print(s.split('!')) # 以!切割
- in 或 not in
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
print('forever' in s ) #True
print('!' not in s) # True
- Length len
s = '123'
print(len(s)) # 3 # 求字符串的长度
2.4 a stored value or a plurality of values
A value
2.5 orderly or disorderly
Ordered
2.6 variable or non-variable (Key)
Variable: The value of constant change id, not a hash
Immutable: variable id value becomes, hashable
Immutable
s2 = 'abc'
print(id(s2))
s2 += 'abc'
print(id(s2))