In Python, data types define the kind of value a variable holds and what operations can be performed on it.
Python is a dynamically typed language, which means you don’t need to explicitly declare variable types — they are determined automatically at runtime.
| Data Type | Example Values | Description |
|---|---|---|
int |
6, 9, -9, 0 |
Represents whole (integer) numbers, positive or negative, without decimals. |
float |
2.3, 4.5, 0.5, -9.8 |
Represents real numbers (decimal values). |
str |
"hello world", "23r08sdh9d" |
Represents a sequence of characters (text). Strings are enclosed in quotes. |
bool |
True, False |
Represents Boolean values — either True or False. |
NoneType |
None |
Represents the absence of a value or a null object. |
# Integer
a = 6
b = -9
# Float
pi = 3.14
temperature = 36.6
# String
message = "Hello World"
code = "23r08sdh9d"
# Boolean
is_active = True
is_logged_in = False
# NoneType
result = NoneTo display output in Python, we use the print() function.
print("Hello World!")Output:
Hello World!
You can print multiple values as well:
x = 10
y = 5
print("Sum:", x + y)Output:
Sum: 15
The type() function in Python returns the data type of a given object.
type(object)print(type("True")) # String
print(type("Hello")) # String
print(type(2)) # Integer
print(type(2.3)) # Float
print(type(None)) # NoneType
print(type(True)) # Boolean<class 'str'>
<class 'str'>
<class 'int'>
<class 'float'>
<class 'NoneType'>
<class 'bool'>
Note: The output format
<class 'typename'>shows that in Python, everything is an object of a specific class.
Python allows you to convert between data types using built-in functions such as int(), float(), and str().
num = "10"
print(int(num)) # Converts string to integer → 10
print(float(num)) # Converts string to float → 10.0
print(str(20)) # Converts integer to string → "20"Output:
10
10.0
20
- Python automatically infers the type of a variable at runtime.
- Use
type()to check what data type a value or variable has. - Convert between data types using casting functions like
int(),float(), andstr(). Nonerepresents the absence of a value — it’s not the same as0orFalse.
- Create variables of each type (
int,float,str,bool,None) and print their types. - Convert a string
"100"into both an integer and a float. - Create a Boolean variable and print its type using the
type()function. - Experiment with
None— assign it to a variable and print its type.