Python数据类型
1、字符串(str)
str3 = """I miss you so much"""
print("str3 = ", str3,type(str3))
str3 = I miss you so much <class 'str'>
2、整数(int)
str1 = 55
print("str1 = ", str1,type(str1))
str1 = 55 <class 'int'>
3、浮点数(float)
str2 = 55.5
print("str2 = ", str2,type(str2))
str2 = 55.5 <class 'float'>
4、布尔值(bool)
str6 = True
print("str6 = ", str6,type(str6))
str6 = True <class 'bool'>
5、列表(list)
str4 = ['''I miss you so much''']
print("str4 = ", str4,type(str4))
str4 = ['I miss you so much'] <class 'list'>
6、元组(tuple)
str5 = (1,2,3)
print("str5 = ", str5,type(str5))
str5 = (1, 2, 3) <class 'tuple'>
7、字典(dict)
print("str7 = ", str7,type(str7))
str7 = {"name": "Bob", "age": 30}
str7 = {'name': 'Bob', 'age': 30} <class 'dict'>
8、集合(set)
str8 = {1, 2, 2, 3}
print("str8 = ", str8,type(str8))
str8 = {1, 2, 3} <class 'set'>
索引
序列中的每个元素都有一个编号,也称为索引,这个索引是从0开始的,即下标为0的是第一个元素,下标为1的是第二个元素
s = 'hello'
print(s[0])
print(s[-1])
print(s[::2])
print(s[1::2])
print(s[4])
print(s[::])
print(s[0:-1])
for i in range(len(s)):print(i,s[i])