LearnFromHome
Login / register

Python

LearnFromHome > coding > python

Python is a popular, high-level programming language known for its readability and versatility.

150 followers

Python Variables and Data Types

Learn how Python handles data and how to store it using variables.

What is a Variable?

A variable is like a container that holds information you can use later. In Python, you don't need to declare a variable's type—just assign a value using the = operator.

name = "Alice"
age = 25
is_student = True

Common Data Types

  • String – Textual data, written in quotes: "Hello"
  • Integer – Whole numbers like 5 or -2
  • Float – Numbers with decimals, like 3.14
  • Boolean – True or False values

Type Checking

You can check the type of any variable using the type() function:

print(type(name)) # Output: <class 'str'>
print(type(age)) # Output: <class 'int'>

Dynamic Typing

Python uses dynamic typing, which means you can change a variable's value and even its type without errors:

data = 42
print(type(data)) # int
data = "Now I'm a string!"
print(type(data)) # str

Next: Control Flow in Python →