数据类型的汇总和功能

常用数据类型有:int整型、bool布尔值、str字符串、list列表、tuple元组

1、int 整型

强制转换:

int("字符串")

int(布尔值)

2、bool布尔值

除了0、[]空列表、()空元组、""空字符串,是false,其他都是true

3、str字符串

独有功能:upper/lower/split/strip/replace/isdigit/starswith/endswith/format/join/encode

公共功能:len、索引、切片、步长、for循环

强制转换:

str(999)→"999"

str(True)→"True"

4、list列表

独有功能:append/insert/pop/remove/clear/extend

公共功能:len、索引、切片、步长、for循环、删除、更新

强制转换:

list((334,123,1234,5435))→[334,123,1234,5435]

5、tuple元组

独有功能:无

公共功能:len、索引、切片、步长、for循环

强制转换:

tuple([334,123,1234,5435])→(334,123,1234,5435)

总结:

最常用的转换有:

1、字符串转数字

2、数字转字符串

3、列表转元组

4、元组转列表

5、其他转bool时,只有:0、[]空列表、()空元组、""空字符串是Flase,其他都是True

原文地址:https://www.cnblogs.com/meng-xiaoyi/p/14111955.html