Lesson 2.1: Python Basics – Variables, Data Types, Operators
1. Introduction
Python is the most widely used programming language in Data Science because it is simple, readable, and has a huge set of libraries. Before moving into advanced concepts like NumPy, Pandas, or Machine Learning, you must understand Python basics.
2. Variables in Python
-
A variable is used to store data.
-
In Python, you don’t need to declare the type explicitly (dynamic typing).
Examples:
👉 Rule: Variable names must start with a letter or underscore, and cannot contain spaces or special symbols.
3. Data Types in Python
Python has several built-in data types:
-
Numeric Types
-
int→ whole numbers (e.g., 5, 100) -
float→ decimal numbers (e.g., 3.14, 99.9) -
complex→ complex numbers (e.g., 2 + 3j)
-
-
Text Type
-
str→ sequence of characters (e.g., “Data Science”)
-
-
Boolean Type
-
bool→TrueorFalse
-
-
Sequence Types
-
list,tuple,range
-
-
Mapping Type
-
dict(dictionary with key-value pairs)
-
-
Set Types
-
set,frozenset
-
Example:
4. Operators in Python
Operators are symbols used to perform operations on variables and values.
-
Arithmetic Operators
-
+Addition -
-Subtraction -
*Multiplication -
/Division (float) -
//Floor Division (integer result) -
%Modulus (remainder) -
**Exponentiation
-
-
Comparison Operators
-
==Equal to -
!=Not equal to -
>Greater than -
<Less than -
>=Greater than or equal to -
<=Less than or equal to
-
-
Logical Operators
-
and,or,not
-
-
Assignment Operators
-
=,+=,-=,*=,/=, etc.
-
-
Membership Operators
-
in,not in
-
-
Identity Operators
-
is,is not
-
5. Key Takeaways
-
Variables store values and are dynamically typed in Python.
-
Data types define the nature of stored values (int, float, str, list, dict, etc.).
-
Operators help perform calculations, comparisons, and logic operations.
✅ With this foundation, you are ready to control the flow of programs using if-else and loops in the next lesson.
