一、Python的七种基本数据类型
Python中的数据类型:
整型: int 1, 0, -1, -2,
浮点型: float 1.11, 0.22
复数:complex a + bj
字符串:str
1.1, 1, '1.1', "1"
''或者""或者'''或者""" 123, 1'2'3
字节:bytes: b'\xe4\xb8\xad\xe6\x96\x87'
布尔: bool: True , False
空类型: None
代码如下
int_var = 1 float_var = 1.1 bool_var = True bytes_var = b'123' str_var = "123" none_var = None complex_var = 1+2j print("variable name is int_var", "value is", int_var, "type is", type(int_var)) print("variable name is float_var", "value is", float_var, "type is", type(float_var)) print("variable name is bool_var", "value is", bool_var, "type is", type(bool_var)) print("variable name is bytes_var", "value is", bytes_var, "type is", type(bytes_var)) print("variable name is str_var", "value is", str_var, "type is", type(str_var)) print("variable name is none_var", "value is", none_var, "type is", type(none_var)) print("variable name is complex_var", "value is", complex_var, "type is", type(complex_var))
二、字符串的定义
print("i am a boy", end=" ") print("666") print('i am a boy', end=" ") print('666') print("""i am a boy""", end=" ") print("""666""") print('''i am a boy''', end=" ") print('''666''')
三、序列
str_data = "1234567890" list_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] print(list_data[1]) print(list_data[-9]) print(list_data[2]) print(list_data[-8]) print(list_data[3]) print(list_data[-7]) print(list_data[4]) print(list_data[-6])
四、总结
Python的简单数据类型介绍和序列以及字符串的定义