1. 字符串 str
str1 = "westos"
str2 = 'westos'
str3 = """ *** 字符串 *** """
print(str1, type(str1))
print(str2, type(str2))
print(str3, type(str3))
![在这里插入图片描述](https://img-blog.csdnimg.cn/748a57a7b7944e89b0bdc770d54c7da9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAT3V0bG9vayheX14p,size_13,color_FFFFFF,t_70,g_se,x_16)
2. 列表 list
- 数组:只能存储同一种数据类型数据的结构,使用
[ ]
- 列表 可以存储不同数据类型数据,使用
[ ]
,可以对列表内的数据进行增删改查
list1 = [1, 2, 3, 4]
list2 = [1, 2, 2e+5, 3.14, True, [1, 2, 3]]
print(list1, type(list1))
print(list2, type(list2))
![在这里插入图片描述](https://img-blog.csdnimg.cn/68f31f14f9bb483bb071f6aab06767a3.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAT3V0bG9vayheX14p,size_18,color_FFFFFF,t_70,g_se,x_16)
3. 元组 tuple
- 元组 和 列表 类似,但是,唯一的区别在于,元组中的数据不能进行增删改,使用
[ ]
- 注意:对于元组中只有一个元素时,需要在最后一个元素后写上一个都好
,
;否则,打印出的数据不是元组类型
t1 = (1, 2, 2e+5, True, 3.14, [1, 2, 3])
print(t1, type(t1))
t2 = (1)
print(t2, type(t2))
t3 = (1,)
print(t3, type(t3))
t4 = (True)
print(t4, type(t4))
t5 = (True,)
print(t5, type(t5))
![在这里插入图片描述](https://img-blog.csdnimg.cn/e4e0ec9e577d449e815357f6d5c09eef.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAT3V0bG9vayheX14p,size_19,color_FFFFFF,t_70,g_se,x_16)
4. 集合 set
- 集合 中的数据不会重复,且是无序的
- 使用
{ }
- 使用 set.add() 增加数据,注意插入的顺序与最终的顺序不同
- 集合可以求交集和并集
set1 = {1, 2, 3, 1, 2, 3, 4}
print(set1, type(set1))
set2 = {1, 2, 3, 2, 3, 20}
set2.add(18)
print(set2, type(set2))
print( set1 & set2 )
print( set1 | set2)
![在这里插入图片描述](https://img-blog.csdnimg.cn/a08fe66ab54f480cb6a759d1d8252a72.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAT3V0bG9vayheX14p,size_13,color_FFFFFF,t_70,g_se,x_16)
5. 字典 dict
- 字典 根据关键字找到对应的值,
- key 和 value ,根据key,可以找到value
user1 = { "name":"admin", "password" : "westos" }
print(user1, type(user1))
![在这里插入图片描述](https://img-blog.csdnimg.cn/de523cc77de149f4ac74d276af7921f1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAT3V0bG9vayheX14p,size_19,color_FFFFFF,t_70,g_se,x_16)