一、数据类型
1、数字int(整型)
long(长整型)
float(浮点型)
complex(复数)
2、布尔值True或False
3、字符串
二、变量
变量命名规则:变量名只能是 字母、数字或下划线的任意组合
变量名的第一个字符不能是数字
变量名不能为关键字(例如:and,or,continue,break,in,else,print 等)
三、字符串拼接
1、使用加号(+)name = "Tom"age = 25print(name + "s age is " + str(age))
#输出:Toms age is 25
2、字符串格式化name = = 25( %
ps:在python中,使用+号连接字符串,每出现一个+号,就要重新在内存中申请一块空间,有多少个+号,就要申请多少块空间。一般不建设使用+号连接字符串。
四、列表和元组
1、列表(list)创建列表
002pc.com对《python3 经典代码关于python3学习基础知识总结》总结来说,为我们学习编程很实用。str_list = ['Tom','Lucy','Mary']
或者
str_list = list(['Tom','Lucy','Mary'])索引(访问列表中某一个值)str_list[0]追加(增加元素到末尾)str_list.append('lilei')print(str_list)#输出:['Tom', 'Lucy', 'Mary', 'lilei']插入(在指定位置加入元素)str_list.insert(1,'lilei')print(str_list)#输出:['Tom', 'lilei', 'Lucy', 'Mary']删除(删除指定元素)str_list.remove('Lucy')print(str_list)#输出:['Tom', 'Mary']切片str_list = [3,4,5,6,7,8,9]
new_1 = str_list[1:3] #从索引1开始取,取到索引3
new_2 = str_list[0:6:2] #从索引0开始取,每两位一取,到第6位为止
new_3 = str_list[-2:] # 取后面2个数
new_4 = str_list[:3] # 取前面3个数
new_5 = str_list[::3] #所有数,每3个取一个
print(new_1,new_2,new_3,new_4,new_5)
#输出:[4, 5] [3, 5, 7] [8, 9] [3, 4, 5] [3, 6, 9]
2、元组(tuple)创建元组age = (18,25,33)
或者
age = tuple((18,25,33))
除了不能修改、增加、删除元素,其它操作元组和列表几乎一样。
五、字典
更多:python3 经典代码关于python3学习基础知识总结
https://www.002pc.comhttps://www.002pc.com/python/3225.html
你可能感兴趣的python3,基础知识,总结,学习,关于
No alive nodes found in your cluster
0踩
赏
0 赞