What are different Python Data Types - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
Data Type represents a type of data present in a variable. In this tutorial, we will see what are the different types of  Python data types.
As we seen in Advantages of Python, in Python, we are not required to specify a type explicitly to a variable. Based on the value provided to the variable, the type will be assigned automatically. Hence the Python is consider to be a dynamically typed language.

int
float
complex
bool
str
bytes
bytearray
range
list
tuple
set
frozenset
dict
None

int
float
complex
bool
str
bytes
bytearray
range
list
tuple
set
frozenset
dict
None
The above mentioned data types are inbuilt data types. Based on the value present in side the variable Python internally assigns these data types to a variable.
Though these are assigned by the python internally, if we really want to check the type of a variable, python given us an inbuilt function called type() it gives us the type of a variable.
We can use the int data type to represent numbers.
x = 10
type(a)
<class 'int'>
float data type represents the decimal/floating point numbers.
>>>x=10.5
>>>type(x)
<class 'float'>
Python complex datatype holds complex numbers, its basically a combination of real and imaginary numbers.
>>>x = 10+5j
>>>type(c)
<class 'complex'>
>>>c.real
10.0
>>>c.imag
5.0
Bool datatype represents logical values, it only holds either True or False.
>>>flag=True
>>>flag=False
>>>type(flag)
<class 'bool'>
Python Str datatype represents a sequence of characters.
>>>s='chandra'
>>>type(s)
<class 'str'>
>>>s='chandra shekhar goka'
>>>type(s)
<class 'str'>
bytes datatype represents a sequence of byte values with in the range of 0-255.
>>> list=[20,30,40,50]
>>> b=bytes(list)
>>> type(b)
<class 'bytes'>
bytes datatype represents a sequence of byte values with in the range of 0-255. Difference between byte and bytearray is : byte data type is immutable (once it is defined we can’t change it) where as bytearray datatype mutable (we can change the values after defining).
>>>list=[50,60,70]
>>>barray= bytearray(list)
>>>type(barray)
<class 'bytearray'>
range datatype is used to define a range of values.
>>>r=range(10)
>>>r1=range(0,50)
>>>r2=range(0,50,10)
list datatype represents an ordered collection of objects.
>>>l=[1,5,6,7,8,9]
>>>type(l)
<class 'list'>
tuple datatype represents an ordered collection of objects. The only difference between list vs tuple is : list is an mutable ordered collection where as tuple is immutable ordered collection.
>>>t=(1,5,6,7,8,9)
>>>type(t)
<class 'tuple'>
Set represents an un-ordered collection of unique objects. it doesn’t allowed duplicate values inside it. Set is an mutable collection.
>>>s={1,2,4,3,5,7,6,9}
>>>type(s)
<class 'set'>

frozenset represents an un-ordered collection of unique objects. it doesn’t allowed duplicate values inside it. frozenset is an immutable collection.
>>>s={10,20,'chandra',50,'shekhar'}
>>>fs = frozenset(s)
>>>type(fs)
<class 'frozenset'>
dict represents a group of key->value pairs.
>>>d={100:'JAVA',101:'Python',102:'PHP'}
>>>type(d)
<class 'dict'>
If a variable or def, doesn’t having any value init, the default datatype is None.
>>>def sample():
>>>a=20
>>>print(sample())
None
Happy Learning 🙂

Different ways to do String formatting in Python
How to remove special characters from String in Python
Python List comprehension usage and advantages
Organization of data In Data Structures
How to create Python Iterable class ?
What is Python NumPy Library
How to get Characters Count in Python from a File
Python TypeCasting for Different Types
Python List Data Structure In Depth
Python Tuple Data Structure in Depth
PHP Data types Example Tutorials
Python Set Data Structure in Depth
Python Operators Example
Features of Python Language
Modes of Python Program

Different ways to do String formatting in Python
How to remove special characters from String in Python
Python List comprehension usage and advantages
Organization of data In Data Structures
How to create Python Iterable class ?
What is Python NumPy Library
How to get Characters Count in Python from a File
Python TypeCasting for Different Types
Python List Data Structure In Depth
Python Tuple Data Structure in Depth
PHP Data types Example Tutorials
Python Set Data Structure in Depth
Python Operators Example
Features of Python Language
Modes of Python Program
 


Δ
 Python – Introduction
 Python – Features
 Python – Install on Windows
 Python – Modes of Program
 Python – Number System
 Python – Identifiers
 Python – Operators
 Python – Ternary Operator
 Python – Command Line Arguments
 Python – Keywords
 Python – Data Types
 Python – Upgrade Python PIP
 Python – Virtual Environment
 Pyhton – Type Casting
 Python – String to Int
 Python – Conditional Statements
 Python – if statement
 Python – *args and **kwargs
 Python – Date Formatting
 Python – Read input from keyboard
 Python – raw_input
 Python – List In Depth
 Python – List Comprehension
 Python – Set in Depth
 Python – Dictionary in Depth
 Python – Tuple in Depth
 Python – Stack Datastructure
 Python – Classes and Objects
 Python – Constructors
 Python – Object Introspection
 Python – Inheritance
 Python – Decorators
 Python – Serialization with Pickle
 Python – Exceptions Handling
 Python – User defined Exceptions
 Python – Multiprocessing
 Python – Default function parameters
 Python – Lambdas Functions
 Python – NumPy Library
 Python – MySQL Connector
 Python – MySQL Create Database
 Python – MySQL Read Data
 Python – MySQL Insert Data
 Python – MySQL Update Records
 Python – MySQL Delete Records
 Python – String Case Conversion
 Howto – Find biggest of 2 numbers
 Howto – Remove duplicates from List
 Howto – Convert any Number to Binary
 Howto  – Merge two Lists
 Howto – Merge two dicts
 Howto – Get Characters Count in a File
 Howto – Get Words Count in a File
 Howto – Remove Spaces from String
 Howto –  Read Env variables
 Howto – Read a text File
 Howto – Read a JSON File
 Howto –  Read Config.ini files
 Howto – Iterate Dictionary
 Howto – Convert List Of Objects to CSV
 Howto – Merge two dict in Python
 Howto – create Zip File
 Howto – Get OS info
 Howto – Get size of Directory
 Howto – Check whether a file exists
 Howto –  Remove key from dictionary
 Howto – Sort Objects
 Howto – Create or Delete Directories
 Howto – Read CSV File
 Howto – Create Python Iterable class
 Howto – Access for loop index
 Howto – Clear all elements from List
 Howto – Remove empty lists from a List
 Howto – Remove special characters from String
 Howto – Sort dictionary by key
 Howto – Filter a list