python学习
http://c.biancheng.net/view/2196.html
1.python注释:单行以#开头,多行是把代码包括在三个单引号‘’‘ ’‘’或者三个双引号“”“ ”“”中。
2.python是一门弱类型语言,特点:
变量无须声明就可以直接赋值,对一个不存在的变量赋值就相当于定义了一个新变量。
变量的数据类型可以随时改变,比如,同一个变量可以一会儿被赋值为整数,一会儿被赋值为字符串。
3. 标识符必须以字母,下划线开头,后面跟数字,字母,下划线。
4.关键字和内置函数
如果开发者尝试使用关键字作为变量名,Python 解释器会报错。
如果开发者使用内置函数的名字作为变量名,Python 解释器倒不会报错,只是该内置函数就被这个变量覆盖了,该内置函数就不能使用了。
5.赋值字符串时要加上双引号,python可以自动拼接字符串,比如:
拼接字符串和数字时,要把数字使用str()或者repr()函数先转化成为字符串,str是内置类型
str()是把字符串内容展示出来,repr()是以python方式展示出来。
6.获取用户输入
2.x版本的raw_input()等于3.x版本的input()
2版本的input()在输入字符串时必须加双引号
7.长字符串:
用三个引号进行定义
使用转移字符进行换行
8.原始字符串
9.字节串
字节串(bytes)和字符串(string)的对比:
字符串由若干个字符组成,以字符为单位进行操作;字节串由若干个字节组成,以字节为单位进行操作。
字节串和字符串除了操作的数据单元不同之外,它们支持的所有方法都基本相同。
字节串和字符串都是不可变序列,不能随意增加和删除数据。
字符串和 bytes 存在着千丝万缕的联系,我们可以通过字符串来创建 bytes 对象,或者说将字符串转换成 bytes 对象。有以下三种方法可以达到这个目的:
如果字符串的内容都是 ASCII 字符,那么直接在字符串前面添加b前缀就可以转换成 bytes。
bytes 是一个类,调用它的构造方法,也就是 bytes(),可以将字符串按照指定的字符集转换成 bytes;如果不指定字符集,那么默认采用 UTF-8。
字符串本身有一个 encode() 方法,该方法专门用来将字符串按照指定的字符集转换成对应的字节串;如果不指定字符集,那么默认采用 UTF-8。
10.格式化字符串
11.指定最小输出宽度
当使用表1中的转换说明符时,可以使用下面的格式指定最小输出宽度(至少占用多少个字符的位置):
%10d 表示输出的整数宽度至少为 10;
%20s 表示输出的字符串宽度至少为 20。
12.指定对齐方式
三个可以单独出现,也可以一起出现
13.指定小数精度
14.获取字符串中的字符
str【】
Python 允许从字符串的两端使用索引:
当以字符串的左端(字符串的开头)为起点时,索引是从 0 开始计数的;字符串的第一个字符的索引为 0,第二个字符的索引为 1,第三个字符串的索引为 2 ……
当以字符串的右端(字符串的末尾)为起点时,索引是从 -1 开始计数的;字符串的倒数第一个字符的索引为 -1,倒数第二个字符的索引为 -2,倒数第三个字符的索引为 -3 ……
strname[start : end : step]
对各个部分的说明:
strname:要截取的字符串;
start:表示要截取的第一个字符所在的索引(截取时包含该字符)。如果不指定,默认为 0,也就是从字符串的开头截取;
end:表示要截取的最后一个字符所在的索引(截取时不包含该字符)。如果不指定,默认为字符串的长度;
step:指的是从 start 索引处的字符开始,每 step 个距离获取一个字符,直至 end 索引出的字符。step 默认值为 1,当省略该值时,最后一个冒号也可以省略。
15.title方法
title() 方法用于将字符串中每个单词的首字母转为大写,其他字母全部转为小写,转换完成后,此方法会返回转换得到的字符串。
16.lower方法和upper方法
lower() 方法用于将字符串中的所有大写字母转换为小写字母,转换完成后,该方法会返回新得到的字符串。如果字符串中原本就都是小写字母,则该方法会返回原字符串。
17.去除空格
字符串变量提供了 3 种方法来删除字符串中多余的空格和特殊字符,它们分别是:
strip():删除字符串前后(左右两侧)的空格或特殊字符。
lstrip():删除字符串前面(左边)的空格或特殊字符。
rstrip():删除字符串后面(右边)的空格或特殊字符。
18.除法运算符
/普通除法
//整除
19.次方运算符
** 3**4 3的4次方
20.比较对象引用使用is 和isnot
21.逻辑运算符
and or not
22.三目运算符
max = a if a>b else b
23.元组和列表(元组是不可变的,列表可变)
1)创建列表的语法格式如下:
[ele1,ele2,ele3,…]
创建元组的语法格式如下:
(ele1,ele2,ele3,…)
2)切片
和字符串类似
3)加法拼接元组和列表
4)乘法让元素增加倍数
当元组只有一个元素的时候,必须加逗号
5)in运算符用于判断元组中是否存在元素
6)Python 提供了内置的 ten()、max()、min() 全局函数来获取元组或列表的长度、最大值和最小值。
7)序列封包和解包
序列封包:将10、20、30封装成元组后赋值给vals
vals = 10, 20, 30
print(vals) # (10, 20, 30)
序列解包: 将a_tuple元组的各元素依次赋值给a、b、c、d、e变量
a, b, c, d, e = a_tuple
print(a, b, c, d, e) # 1 3 5 7 9
同时封包和解包:
将10、20、30依次赋值给x、y、z
x, y, z = 10, 20, 30
print(x, y, z) # 10 20 30
8)list()和tuple()函数
list()是把元组和 区间(range)转换成为列表
tuple()是把列表和区间转换成为元组
24.列表添加元素
append() 在添加元组或者列表的时候,会把元组或者列表看做一个整体
extend() 不会看做一个整体,把包含的元素逐个添加
insert() 插入指定位置,index在前,和append一样整体添加
25.删除元素
del listname[index]
删除单个
del listnamme[start:end]
删除一段连续
pop()
不指定的话,默认删除最后一个元素
remove()
根据元素本身的值来进行删除
clear()
清空
26.列表修改元素
修改单个直接赋值
修改连续的进行切片
如果对空切片赋值,相当于插入一组新的元素
volume-19420bd5-d245-426d-b0c1-27a36d54f2d9
{“volume_read_bandwidth”: [{“metric”: {}, “values”: [[1618901700, “0”], [1618901715, “0”], [1618901730, “0”], [1618901745, “0”], [1618901760, “0”], [1618901775, “0”], [1618901790, “0”], [1618901805, “0”], [1618901820, “0”], [1618901835, “0”], [1618901850, “0”], [1618901865, “0”], [1618901880, “0”], [1618901895, “0”], [1618901910, “0”], [1618901925, “0”], [1618901940, “0”], [1618901955, “0”], [1618901970, “0”], [1618901985, “0”], [1618902000, “0”], [1618902015, “0”], [1618902030, “0”], [1618902045, “0”], [1618902060, “0”], [1618902075, “0”], [1618902090, “0”], [1618902105, “0”], [1618902120, “0”], [1618902135, “0”], [1618902150, “0”], [1618902165, “0”], [1618902180, “0”], [1618902195, “0”], [1618902210, “0”], [1618902225, “0”], [1618902240, “0”], [1618902255, “0”], [1618902270, “0”], [1618902285, “0”], [1618902300, “0”], [1618902315, “0”], [1618902330, “0”], [1618902345, “0”], [1618902360, “0”], [1618902375, “0”], [1618902390, “0”], [1618902405, “0”], [1618902420, “0”], [1618902435, “0”], [1618902450, “0”], [1618902465, “0”], [1618902480, “0”], [1618902495, “0”], [1618902510, “0”], [1618902525, “0”], [1618902540, “0”], [1618902555, “0”], [1618902570, “0”], [1618902585, “0”], [1618902600, “0”], [1618902615, “0”], [1618902630, “0”], [1618902645, “0”], [1618902660, “0”], [1618902675, “0”], [1618902690, “0”], [1618902705, “0”], [1618902720, “0”], [1618902735, “0”], [1618902750, “0”], [1618902765, “0”], [1618902780, “0”], [1618902795, “0”], [1618902810, “0”], [1618902825, “0”], [1618902840, “0”], [1618902855, “0”], [1618902870, “0”], [1618902885, “0”], [1618902900, “0”], [1618902915, “0”], [1618902930, “0”], [1618902945, “0”], [1618902960, “0”], [1618902975, “0”], [1618902990, “0”], [1618903005, “0”], [1618903020, “0”], [1618903035, “0”], [1618903050, “0”], [1618903065, “0”], [1618903080, “0”], [1618903095, “0”], [1618903110, “0”], [1618903125, “0”], [1618903140, “0”], [1618903155, “0”], [1618903170, “0”], [1618903185, “0”], [1618903200, “0”], [1618903215, “0”], [1618903230, “0”], [1618903245, “0”], [1618903260, “0”], [1618903275, “0”], [1618903290, “0”], [1618903305, “0”], [1618903320, “0”]]}], “volume_read_iops”: [{“metric”: {}, “values”: [[1618901700, “0”], [1618901715, “0”], [1618901730, “0”], [1618901745, “0”], [1618901760, “0”], [1618901775, “0”], [1618901790, “0”], [1618901805, “0”], [1618901820, “0”], [1618901835, “0”], [1618901850, “0”], [1618901865, “0”], [1618901880, “0”], [1618901895, “0”], [1618901910, “0”], [1618901925, “0”], [1618901940, “0”], [1618901955, “0”], [1618901970, “0”], [1618901985, “0”], [1618902000, “0”], [1618902015, “0”], [1618902030, “0”], [1618902045, “0”], [1618902060, “0”], [1618902075, “0”], [1618902090, “0”], [1618902105, “0”], [1618902120, “0”], [1618902135, “0”], [1618902150, “0”], [1618902165, “0”], [1618902180, “0”], [1618902195, “0”], [1618902210, “0”], [1618902225, “0”], [1618902240, “0”], [1618902255, “0”], [1618902270, “0”], [1618902285, “0”], [1618902300, “0”], [1618902315, “0”], [1618902330, “0”], [1618902345, “0”], [1618902360, “0”], [1618902375, “0”], [1618902390, “0”], [1618902405, “0”], [1618902420, “0”], [1618902435, “0”], [1618902450, “0”], [1618902465, “0”], [1618902480, “0”], [1618902495, “0”], [1618902510, “0”], [1618902525, “0”], [1618902540, “0”], [1618902555, “0”], [1618902570, “0”], [1618902585, “0”], [1618902600, “0”], [1618902615, “0”], [1618902630, “0”], [1618902645, “0”], [1618902660, “0”], [1618902675, “0”], [1618902690, “0”], [1618902705, “0”], [1618902720, “0”], [1618902735, “0”], [1618902750, “0”], [1618902765, “0”], [1618902780, “0”], [1618902795, “0”], [1618902810, “0”], [1618902825, “0”], [1618902840, “0”], [1618902855, “0”], [1618902870, “0”], [1618902885, “0”], [1618902900, “0”], [1618902915, “0”], [1618902930, “0”], [1618902945, “0”], [1618902960, “0”], [1618902975, “0”], [1618902990, “0”], [1618903005, “0”], [1618903020, “0”], [1618903035, “0”], [1618903050, “0”], [1618903065, “0”], [1618903080, “0”], [1618903095, “0”], [1618903110, “0”], [1618903125, “0”], [1618903140, “0”], [1618903155, “0”], [1618903170, “0”], [1618903185, “0”], [1618903200, “0”], [1618903215, “0”], [1618903230, “0”], [1618903245, “0”], [1618903260, “0”], [1618903275, “0”], [1618903290, “0”], [1618903305, “0”], [1618903320, “0”]]}], “volume_read_latency”: [{“metric”: {}, “values”: [[1618901700, “0”], [1618901715, “0”], [1618901730, “0”], [1618901745, “0”], [1618901760, “0”], [1618901775, “0”], [1618901790, “0”], [1618901805, “0”], [1618901820, “0”], [1618901835, “0”], [1618901850, “0”], [1618901865, “0”], [1618901880, “0”], [1618901895, “0”], [1618901910, “0”], [1618901925, “0”], [1618901940, “0”], [1618901955, “0”], [1618901970, “0”], [1618901985, “0”], [1618902000, “0”], [1618902015, “0”], [1618902030, “0”], [1618902045, “0”], [1618902060, “0”], [1618902075, “0”], [1618902090, “0”], [1618902105, “0”], [1618902120, “0”], [1618902135, “0”], [1618902150, “0”], [1618902165, “0”], [1618902180, “0”], [1618902195, “0”], [1618902210, “0”], [1618902225, “0”], [1618902240, “0”], [1618902255, “0”], [1618902270, “0”], [1618902285, “0”], [1618902300, “0”], [1618902315, “0”], [1618902330, “0”], [1618902345, “0”], [1618902360, “0”], [1618902375, “0”], [1618902390, “0”], [1618902405, “0”], [1618902420, “0”], [1618902435, “0”], [1618902450, “0”], [1618902465, “0”], [1618902480, “0”], [1618902495, “0”], [1618902510, “0”], [1618902525, “0”], [1618902540, “0”], [1618902555, “0”], [1618902570, “0”], [1618902585, “0”], [1618902600, “0”], [1618902615, “0”], [1618902630, “0”], [1618902645, “0”], [1618902660, “0”], [1618902675, “0”], [1618902690, “0”], [1618902705, “0”], [1618902720, “0”], [1618902735, “0”], [1618902750, “0”], [1618902765, “0”], [1618902780, “0”], [1618902795, “0”], [1618902810, “0”], [1618902825, “0”], [1618902840, “0”], [1618902855, “0”], [1618902870, “0”], [1618902885, “0”], [1618902900, “0”], [1618902915, “0”], [1618902930, “0”], [1618902945, “0”], [1618902960, “0”], [1618902975, “0”], [1618902990, “0”], [1618903005, “0”], [1618903020, “0”], [1618903035, “0”], [1618903050, “0”], [1618903065, “0”], [1618903080, “0”], [1618903095, “0”], [1618903110, “0”], [1618903125, “0”], [1618903140, “0”], [1618903155, “0”], [1618903170, “0”], [1618903185, “0”], [1618903200, “0”], [1618903215, “0”], [1618903230, “0”], [1618903245, “0”], [1618903260, “0”], [1618903275, “0”], [1618903290, “0”], [1618903305, “0”], [1618903320, “0”]]}], “volume_write_bandwidth”: [{“metric”: {}, “values”: [[1618901700, “0”], [1618901715, “0”], [1618901730, “0”], [1618901745, “0”], [1618901760, “0”], [1618901775, “0”], [1618901790, “0”], [1618901805, “0”], [1618901820, “0”], [1618901835, “0”], [1618901850, “0”], [1618901865, “0”], [1618901880, “0”], [1618901895, “0”], [1618901910, “0”], [1618901925, “0”], [1618901940, “0”], [1618901955, “0”], [1618901970, “0”], [1618901985, “0”], [1618902000, “0”], [1618902015, “0”], [1618902030, “0”], [1618902045, “0”], [1618902060, “0”], [1618902075, “0”], [1618902090, “0”], [1618902105, “0”], [1618902120, “0”], [1618902135, “0”], [1618902150, “0”], [1618902165, “0”], [1618902180, “0”], [1618902195, “0”], [1618902210, “0”], [1618902225, “0”], [1618902240, “0”], [1618902255, “0”], [1618902270, “0”], [1618902285, “0”], [1618902300, “0”], [1618902315, “0”], [1618902330, “0”], [1618902345, “0”], [1618902360, “0”], [1618902375, “0”], [1618902390, “1904969.2750795933”], [1618902405, “3907988.4393176944”], [1618902420, “3907988.4393176944”], [1618902435, “3907988.4393176944”], [1618902450, “3907988.4393176944”], [1618902465, “3907988.4393176944”], [1618902480, “3907988.4393176944”], [1618902495, “3907988.4393176944”], [1618902510, “3907988.4393176944”], [1618902525, “3907988.4393176944”], [1618902540, “3907988.464015132”], [1618902555, “3907988.4393176944”], [1618902570, “3907988.4393176944”], [1618902585, “3907988.4393176944”], [1618902600, “3907988.4393176944”], [1618902615, “3907988.4393176944”], [1618902630, “3907988.4393176944”], [1618902645, “3907988.4393176944”], [1618902660, “3907988.4393176944”], [1618902675, “3907988.4393176944”], [1618902690, “2033171.0915254236”], [1618902705, “0”], [1618902720, “0”], [1618902735, “0”], [1618902750, “0”], [1618902765, “0”], [1618902780, “0”], [1618902795, “0”], [1618902810, “0”], [1618902825, “0”], [1618902840, “0”], [1618902855, “0”], [1618902870, “0”], [1618902885, “0”], [1618902900, “0”], [1618902915, “0”], [1618902930, “0”], [1618902945, “0”], [1618902960, “0”], [1618902975, “0”], [1618902990, “0”], [1618903005, “0”], [1618903020, “0”], [1618903035, “0”], [1618903050, “0”], [1618903065, “0”], [1618903080, “0”], [1618903095, “0”], [1618903110, “0”], [1618903125, “0”], [1618903140, “0”], [1618903155, “0”], [1618903170, “0”], [1618903185, “0”], [1618903200, “0”], [1618903215, “0”], [1618903230, “0”], [1618903245, “0”], [1618903260, “0”], [1618903275, “0”], [1618903290, “0”], [1618903305, “0”], [1618903320, “0”]]}], “volume_write_iops”: [{“metric”: {}, “values”: [[1618901700, “0”], [1618901715, “0”], [1618901730, “0”], [1618901745, “0”], [1618901760, “0”], [1618901775, “0”], [1618901790, “0”], [1618901805, “0”], [1618901820, “0”], [1618901835, “0”], [1618901850, “0”], [1618901865, “0”], [1618901880, “0”], [1618901895, “0”], [1618901910, “0”], [1618901925, “0”], [1618901940, “0”], [1618901955, “0”], [1618901970, “0”], [1618901985, “0”], [1618902000, “0”], [1618902015, “0”], [1618902030, “0”], [1618902045, “0”], [1618902060, “0”], [1618902075, “0”], [1618902090, “0”], [1618902105, “0”], [1618902120, “0”], [1618902135, “0”], [1618902150, “0”], [1618902165, “0”], [1618902180, “0”], [1618902195, “0”], [1618902210, “0”], [1618902225, “0”], [1618902240, “0”], [1618902255, “0”], [1618902270, “0”], [1618902285, “0”], [1618902300, “0”], [1618902315, “0”], [1618902330, “0”], [1618902345, “0”], [1618902360, “0”], [1618902375, “0”], [1618902390, “0.4541800677966102”], [1618902405, “0.9317370508474575”], [1618902420, “0.9317370508474575”], [1618902435, “0.9317370508474575”], [1618902450, “0.9317370508474575”], [1618902465, “0.9317370508474575”], [1618902480, “0.9317370508474575”], [1618902495, “0.9317370508474575”], [1618902510, “0.9317370508474575”], [1618902525, “0.9317370508474575”], [1618902540, “0.9317370567357854”], [1618902555, “0.9317370508474575”], [1618902570, “0.9317370508474575”], [1618902585, “0.9317370508474575”], [1618902600, “0.9317370508474575”], [1618902615, “0.9317370508474575”], [1618902630, “0.9317370508474575”], [1618902645, “0.9317370508474575”], [1618902660, “0.9317370508474575”], [1618902675, “0.9317370508474575”], [1618902690, “0.48474576271186437”], [1618902705, “0”], [1618902720, “0”], [1618902735, “0”], [1618902750, “0”], [1618902765, “0”], [1618902780, “0”], [1618902795, “0”], [1618902810, “0”], [1618902825, “0”], [1618902840, “0”], [1618902855, “0”], [1618902870, “0”], [1618902885, “0”], [1618902900, “0”], [1618902915, “0”], [1618902930, “0”], [1618902945, “0”], [1618902960, “0”], [1618902975, “0”], [1618902990, “0”], [1618903005, “0”], [1618903020, “0”], [1618903035, “0”], [1618903050, “0”], [1618903065, “0”], [1618903080, “0”], [1618903095, “0”], [1618903110, “0”], [1618903125, “0”], [1618903140, “0”], [1618903155, “0”], [1618903170, “0”], [1618903185, “0”], [1618903200, “0”], [1618903215, “0”], [1618903230, “0”], [1618903245, “0”], [1618903260, “0”], [1618903275, “0”], [1618903290, “0”], [1618903305, “0”], [1618903320, “0”]]}], “volume_write_latency”: [{“metric”: {}, “values”: [[1618901700, “0”], [1618901715, “0”], [1618901730, “0”], [1618901745, “0”], [1618901760, “0”], [1618901775, “0”], [1618901790, “0”], [1618901805, “0”], [1618901820, “0”], [1618901835, “0”], [1618901850, “0”], [1618901865, “0”], [1618901880, “0”], [1618901895, “0”], [1618901910, “0”], [1618901925, “0”], [1618901940, “0”], [1618901955, “0”], [1618901970, “0”], [1618901985, “0”], [1618902000, “0”], [1618902015, “0”], [1618902030, “0”], [1618902045, “0”], [1618902060, “0”], [1618902075, “0”], [1618902090, “0”], [1618902105, “0”], [1618902120, “0”], [1618902135, “0”], [1618902150, “0”], [1618902165, “0”], [1618902180, “0”], [1618902195, “0”], [1618902210, “0”], [1618902225, “0”], [1618902240, “0”], [1618902255, “0”], [1618902270, “0”], [1618902285, “0”], [1618902300, “0”], [1618902315, “0”], [1618902330, “0”], [1618902345, “0”], [1618902360, “0”], [1618902375, “0”], [1618902390, “0.07674479103956085”], [1618902405, “0.1854321697402007”], [1618902420, “0.1854321697402007”], [1618902435, “0.1854321697402007”], [1618902450, “0.1854321697402007”], [1618902465, “0.1854321697402007”], [1618902480, “0.1854321697402007”], [1618902495, “0.1854321697402007”], [1618902510, “0.1854321697402007”], [1618902525, “0.1854321697402007”], [1618902540, “0.18543217091208217”], [1618902555, “0.1854321697402007”], [1618902570, “0.1854321697402007”], [1618902585, “0.1854321697402007”], [1618902600, “0.1854321697402007”], [1618902615, “0.1854321697402007”], [1618902630, “0.1854321697402007”], [1618902645, “0.1854321697402007”], [1618902660, “0.1854321697402007”], [1618902675, “0.1854321697402007”], [1618902690, “0.11032347584745762”], [1618902705, “0”], [1618902720, “0”], [1618902735, “0”], [1618902750, “0”], [1618902765, “0”], [1618902780, “0”], [1618902795, “0”], [1618902810, “0”], [1618902825, “0”], [1618902840, “0”], [1618902855, “0”], [1618902870, “0”], [1618902885, “0”], [1618902900, “0”], [1618902915, “0”], [1618902930, “0”], [1618902945, “0”], [1618902960, “0”], [1618902975, “0”], [1618902990, “0”], [1618903005, “0”], [1618903020, “0”], [1618903035, “0”], [1618903050, “0”], [1618903065, “0”], [1618903080, “0”], [1618903095, “0”], [1618903110, “0”], [1618903125, “0”], [1618903140, “0”], [1618903155, “0”], [1618903170, “0”], [1618903185, “0”], [1618903200, “0”], [1618903215, “0”], [1618903230, “0”], [1618903245, “0”], [1618903260, “0”], [1618903275, “0”], [1618903290, “0”], [1618903305, “0”], [1618903320, “0”]]}], “ret_code”: “0”, “message”: “”}