栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python Data Types

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python Data Types

Data types specify the differrent sizes and values that can be stored in the variable. For example, Python stores numbers, strings, and a list of values using different data types.

Python is a dynamically typed language. Therefore, we do not need to specify the variable's while declaring it. Whatever value we assign to the variable based on that data type will be automatically assigned. For example, name = 'John' here Python will store the name variable as a str data type.

No matter what value is stored in variable (object), a variable can be any type like int, float, str, list, set, tuple, dict, bool, etc.

There are mainly four types of basic or primitive data types available in Python 

Numeric: int, float, and complex

Sequence: string, list, and tuple

Set

Dictionary(dict)

To check the data type of variable use the built-in function type() and the type() function returns the data type of the variable.

In this article, we will learn the following Python data types in detail. 

Data TypeDescriptionExample
intTo store integer valuesn = 10
floatTo store decimal valuesn = 10.58
complexTo store complex numbers (real and imaginary part)n = 10 + 20j
strTo store textual or string datastr = 'John'
bool To store boolean valuesflag = True
listTo store a sequence of mutable datals = [1, 2, 'John', 'Jenny']
tupleTo store sequence immutable data

t = ( 1, 2, 'a', 'b')

dictTo store key: value pairdic = {1: 'John', 2: 'Jenny'}
setTo store unorder and unindexed valuess = {1, 3, 5}
frozensetTo store immutable version of the setf_set = frozenset({5,7})
rangeTo generate a sequence of numbernumbers = range(10)
bytesTo store bytes valuesb=bytes([1,2,3,5])

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/883491.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号