--- --- restore content begins
A: integer
Uses: used to represent the people of the age level of the phone number, etc. (usually when it plainly is the need to use an integer)
Defined age = 18
Essence: Age = 18 is # Age = int (18 is)
int = ( ' the SR ' ) # error int = ( ' 3.1415926 ' ) # error int = ( ' 12138 ' ) can be converted
PS: int string contains only the pure number into plastic float which also contains although but it contains decimal numbers
Stored-value: access only to a value
Are Ordered: disordered
Whether Variable: immutable type
Conversion between hex
Binary representation by bin:
E.g:
Octal representation by oct:
E.g:
Hexadecimal notation with hex:
E.g:
The remaining band converted to decimal:
Print (int (the X-, Y)) # the X-expressed as the number you want to convert Y denotes what is converted into binary
Variable Type: id becomes the same value can not be represented hash value
Immutable type: vaule showing change id value may be changed a certain hash
String type:
Role: descriptive information such as home address and other appearance
Is defined by: three single quotes double quotation marks
Built-in action:
[1]: according to the index value (positive and negative values, only values)
(1) positive values:
The basic representation: print [variable name (index number)]
test = 'hello world' print(test[0]) # 其取值不是整个字符串的内容 而是字符串里面的单一元素 例如本题取值h
(2)反向取值:
基本表示形式:print[变量名(-索引号)]
test = 'hello world' print(test[-1]) # 其取值不是整个字符串的内容 而是字符串里面的单一元素 例如本题取值d
【2】切片:
基本表示形式:print(变量名[:])
分割:取值的时候可以进行分隔
test = 'hello world' print(test[0:5]) # 其取值不是整个字符串的内容 而是字符串里面的单一元素 例如本题取值hello
步长:隔值取值
基本表示形式:print(变量名[::])
test = 'hello world' print(test[0:5:2]) # 其取值不是整个字符串的内容 而是字符串里面的单一元素 例如本题取值hlo
小特性:
test = 'hello world' print(test[0:5:-1]) # (1)其不会报错 但是也不会打印任何东西 # (2)因为正常情况下打印的为hello 但是此时取反 即从右边对左边去 但是左边没有任何数据
解决办法
test = 'hello world' print(test[5:0:-1]) # 打印出来 olle
PS:
(1)切片默认从左到右的
(2)规定左边为头 右边为尾
(3)顾头不顾尾
(4)步长默认为1
【3】
len长度:看数据类型的长度
基本表示形式:print(len(变量名))
(1)其在字符串中统计的是字符串中字符的个数
(2)在容器类型数据中 统计的是容器中的个数
例如:
test = 'hello world' print(len(test)) # 其打印结果为11 空格也属于字符 test ={'name':'se','age':18 ,'hob':'read'} print(len(test)) # 其打印结果为3
【4】
in/not in:
作用:查看某些字符串是否属于更大的字符串
表现形式:print(变量名 in/not in 变量名)
例如:
test = 'SR' test1 = 'SR love music' print(test in test1) # 返回值true test = 'SR' test1 = 'sr love musci' print(test not in test1) # 返回值true
【5】
strip:
作用:去掉字符串左右两边的字符 但是对中间的没有影响
基本表现形式:print(变量名.strip('符号'))
例如:
test = '$$$lo$ve$$$' print(test.strip('$')) # 打印内容lo$ve
rstrip:去除字符串右边的字符
例如:
test = 'love$$$' print(test.rstrip('$')) # 打印结果love
lstrip:去除字符串左边的字符
例如:
test = '¥¥¥love' print(test.lstrip('¥¥¥')) # 打印结果love
---恢复内容结束---