0% found this document useful (0 votes)
5 views1 page

Data Types in Python

The document outlines the 14 data types in Python, including numbers (integers, floats, and complex), boolean, and strings. It discusses type casting, the distinction between mutable and immutable data types, and the concept of object reusability in Python. Key examples illustrate how integers and strings behave with respect to mutability and memory efficiency.

Uploaded by

rathimanish5143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Data Types in Python

The document outlines the 14 data types in Python, including numbers (integers, floats, and complex), boolean, and strings. It discusses type casting, the distinction between mutable and immutable data types, and the concept of object reusability in Python. Key examples illustrate how integers and strings behave with respect to mutability and memory efficiency.

Uploaded by

rathimanish5143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

There are total 14 data types in python.

Let’s have look at them

Numbers in python:-
1. Integers
2. Float
3. Complex

Integers in Python

Base conversion:-

NOTE:- To convert any number from binary, octal, hexadecimal to decimal value just assign the value
to a variable with corresponding prefixed and peint it. It will give you decimal equivalent of that
number.

Floats in Python:-

Complex numbers in Python

Boolean Data Type in Python

Strings in Python

Type Casting/Type Conversion in Python:-

Mutable vs Immutable Data type in Python:-


Mutable —> Modifiable
Immutable —> Not modifiable —> The concept of immutability says that if you would try
to modify the existing object then instead of making the changes to existing object
PVM creates a new object for those which are immutable.
>>> a = 10
>>> id(a)
46783421
>>> a = a+1
>>> a
11
>>> id(a)
67534215

In some case, it may not be allowed to make the changes also.


>>> a = ‘Python’
>>> a[0] = ‘J’
TypeError: 'str' object does not support item assignment

Object Reusability in Python:-


1. Everything is object in Python.
2. Creating objects in other programming languages is bit costly.
3. Objects get created at time when we launch python for the most frequently used
values/objects.
4. Available only for Fundamental data types including None, not for derived data
types. But derived data types follow object reusability internally.
5. Object reusability concept is used to efficiently utilise the memory.

You might also like