Python必须掌握的200道面试题

基础笔试题

基础算法题

首页 > Python必须掌握的200道面试题 > 基础笔试题 > 1.5节:Python的基础数据类型有哪些?

1.5节:Python的基础数据类型有哪些?

薯条老师 2020-06-16 10:28:55 234019 0

编辑 收藏

教程引言:

荟萃经典的Python面试题,包括但不限于基础知识,高阶知识,算法,以及开放性回答等必考的面试题。

Python的基础数据类型有哪些?

Python的基础数据类型,可分为简单数据类型和复合数据类型。简单数据类型是不可再分割的原子数据类型,Python中的简单数据类型有:整型,浮点类型,布尔类型复合数据类型由简单数据类型或其它复合数据类型组合而成,是一种可以存储其它数据类型的数据集合,在Python中也被成为容器类数据类型。Python中的复合数据类型有字符串,列表,元组,字典,集合

通过内置的type,可以输出数据类型的类型名:

# 在type的输出中,class后面用引号括住的即为数据类型的类型名
class_name = type(2020)
# class_name的输出为<class 'int'>,int即为整型的类型名

class_name = type(20.1314)
# class_name的输出为<class 'float'>,float即为浮点类型的类型名

class_name = type(True)
# class_name的输出为<class 'bool'>,bool即为布尔类型的类型名



class_name = type('Python')
# class_name的输出为<class 'str'>,str即为字符串类型的类型名

class_name = type([1,2,3])
# class_name的输出为<class 'list'>,list即为列表类型的类型名
 
class_name = type((1,2,3))
# class_name的输出为<class 'tuple'>,tuple即为元组类型的类型名

class_name = type({0: 'ok', 1: 'invalid parameters'})
# class_name的输出为<class 'dict'>,dict即为字典类型的类型名

class_name = type({'Python', 'C++', 'Java'})
# class_name的输出为<class 'set'>,set即为集合类型的类型名

关注微信公众号:薯条编程,公众号后台回复"Python资料",免费领取Python电子书,以及学习Python视频课程。

小班授课,薯条老师一对一教学,火热报名中,点击了解线下就业培训。


欢迎 发表评论: