Python Data Types

Python Data Types

In Python, data types are used to classify the type of data that a variable holds. Since Python is a dynamically typed language, you don’t need to specify the type of a variable explicitly. Python automatically assigns the appropriate type based on the value you assign to the variable. Understanding data types is essential for writing effective Python code.

Commonly used Data types:
Data Type What it holds Example Precision
int Whole numbers x = 10 Precision depends on the system’s memory
float Numbers with decimals y = 10.5 Up to 15-17 decimal places (machine-dependent)
str Text (strings of characters) name = “Alice” Determined by the number of characters
bool Boolean values (True/False) is_active = True 1-bit (True or False)
None Represents the absence of value result = None No precision (represents null or no value)

1. int (Integer): Represents whole numbers without a decimal.

Example:

age = 25
#here age is variable name and 25 is integer value of this variable
#python dynamically decides the datatype of a variable based on #value

2. float (Floating-point): Represents numbers with a decimal point.

Example:

weight = 55.5
#here weight is variable and 55.5 is float value of this variable

3. str (String): Represents sequences of characters enclosed in quotes.

Example:

name = ‘Xyz’
#here name is variable and Xyz is string value of this variable

4. bool (Boolean): Represents True or False values.

Example:

is_active = True
#here is_active is variable and True is boolean value of variable

Note: Boolean can either be True or False.
is_active = True and is_active = ‘True’ are two different data types. True without
quotation represents boolean while ‘True’ with quotation represents a string

5. none: Represents the absence of a value or a null value.

Example:

val = None
#here val is variable name and None is none value of this variable

Course Video

YouTube Reference :