Types of Data in Python and its Examples

0
146

Introduction To Types Of Data In Python

Data types in Python are the classification or separation of data items. Data types represent a kind of value that determines what operations can be performed on that data. Numeric, non-numeric, and Boolean (T/F) data are the most used data types. First up is a discussion of the basic data types that are built into Python. And also get an overview of Python’s built-in functions. These are pre-written chunks of code you can call to do useful things.

Python has the following standard or built-in data types:

Numeric

A numeric value is any representation of data that has a numeric value. 

In Python three types of numbers: 

Integers

Positive or negative whole numbers (without a fractional part).In Python, no limit to how long an integer value can be.  

print(100)
PrefixInterpretationBase
0b (zero + lowercase letter ‘b’)0B (zero + uppercase letter ‘B’)Binary2
0o (zero + lowercase letter ‘o’)0O (zero + uppercase letter ‘O’)Octal8
0x (zero + lowercase letter ‘x’)0X (zero + uppercase letter ‘X’)Hexadecimal16
>>> print(0o10)
8

>>> print(0x10)
16

>>> print(0b10)
2

Float: Float values are specified with a decimal point. For Example 3.14


3.14
type(3.14)
<class 'float'>

Complex Number:

A combination of numbers with a real and imaginary component represented as x+yj.
Here, x and y are floats
j is -1(square root of -1 called an imaginary number)



 5+7j
 (5+7j)
 type(5+7j)
 <class 'complex'>

Boolean

Data with one of two built-in values True or False. 

Note: In python ‘T’ and ‘F’ are capital. 

For Example:

 type(T)
 <class 'bool'>
 type(F)
 <class 'bool'>

Sequence Types In Python

A sequence is an ordered collection of similar or different data types. 

Following are sequence types in Python: 

String

Strings are sequences of character data(i.e. No Numeric). The string type in Python is called str. A string value is put in single, double, or triple quotes.

 print(“Fireblaze AI School”)

 Fireblaze AI School.

 type("Fireblaze AI School.")

 <class 'str'>

List

A list object is an ordered collection of one or more data items, not necessarily of the same data type, put in square brackets i.e.[“a”,”b”,”c”,”d”].

Tuple

A Tuple object is an ordered collection of one or more data items, not necessarily of the same type, put in parentheses It means round bracket i.e. (1,2,4,3).

Dictionary 

A dictionary object is an unordered collection of data in a key: value pair format. 

A collection of such pairs is enclosed in curly ‘{}’ brackets. 

For example {1: “Fireblaze”, 2: “AI”, 3: “School”}

Conclusion

In this article, you learned about the built-in data types and functions Python provides.The examples given so far have all manipulated and displayed only constant values. 

LEAVE A REPLY

Please enter your comment!
Please enter your name here