一、python中变量的定义:(显式的定义)
1、int (整型)
int_data = 1
2、float (浮点型)
float_data = 1.1
3、complex (复数)
complex_data = 1+2j
4、bool (波尔型)
bool_data = Ture
bool_data = False
5、None (空类型)
none_data = None
6、bytes (字节型)
bytes_data = b'abc'
7、str (字符串)
str_data = "Today is sunny"
8、tuple (元组)(数组一样的结构)(element1,element2...)里面有多个元素,顺序存储的结构,可以存储不同类型元素。
tuple_data = (1, 2, 3, 4)
list: 列表,【】里面有多个元素,顺序存储结构,列表可扩展(可变的)
可以存储不同类型元素
dict: dictionary的缩写,字典的意思
key: value一个元素,键值对
每一个元素包含两部分:key:键,value:值
字典里的key是唯一的,字典的key和value,也可以是多种类型
字典的key必须不可变
展示的形式:{key:value,key2:value...}
set:集合:并集,差集,交集
无序,不重复,集合中的元素是无序且不重复
1,2,3,4,1,2,5
展示形式:{1,2,3,4,5}可以存储不同类型元素
二、使用类型转换定义变量
1、int (整型)
int_data = 1
float_data = float(1)
complex_data = complex(1)
bool_data = bool(1)
bytes_data = bytes(1)
str_data = str(1)
tuple_data = tuple(1,)
将整型转化为浮点型、复数、波尔、字节型、字符串和元组
tuple转换时只有可迭代型可以转换::list,字符串,dict,元组,生成器等
| Built-in immutable sequence.
内建的不可变序列
immutable:不可变的
sequence:序列
tuple(iterable=())
#iterable:可迭代的
#序列:tuple,str,bytes 目前为止学到序列,也是可迭代的对象
If no argument is given, the constructor returns an empty tuple.
If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
#操作tuple的方法:
count(value)
#计数
Return number of occurrences of value
#返回你给定的value出现的次数