python类型强转&二级容器

时间:2023-02-13 12:07:37

Number 类型强转

int :          ---->>>          float,  bool,  complex,  str

Float :        ---->>>              int(舍弃小数位),  bool,  complex, str

Complex :  ---->>>                str,  bool

Bool :          ---->>>               str,  int, float, complex

 

容器类型强转:

Str :       <<<----              Number,  list,  set,  dict,  tuple

List:       <<<----                str, set, dict, tuple

Tuple     <<<----                  str, list, dict, set

Set         <<<----              str, list, tuple, dict (相同的值, 自动去重)

Dict: 二级列表, 二级元祖, 二级集合(无序, 不推荐),  二级元素若是字符串那么就只能有两个字符

 

 

关于二级容器的问题:

二级容器:  自己本身是一个容器,里面的元素还是一个容器类型数据

等长二级容器:  里面都是容器类型数据,每个容器里面元素个数都一样

强转字典必须是等长的二级容器,并且里面元素的个数是2个