Python is a high-level, interpreted, and dynamically typed programming language known for its simplicity and readability. It was created by Guido van Rossum and first released in 1991. Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming. It is widely used in web development, data science, machine learning, automation, and more. Python’s syntax is concise and easy to understand, making it a preferred language for beginners and professionals alike.
1. Variables and Assignment Statements
Variables in Python
A variable in Python is a name that stores a value. Unlike other programming languages, Python does not require explicit declaration of variables; it automatically assigns the data type based on the assigned value.
Variable Declaration and Assignment
Variables are assigned using the = operator. Example:
x = 10 # Integer
name = “John” # String
pi = 3.14 # Float
is_valid = True # Boolean
-
Variables must start with a letter or underscore (_) but cannot start with a digit.
-
They cannot use Python reserved keywords (e.g.,
if,while,def). -
Python is case-sensitive, meaning
varandVarare different.
2. Data Types in Python
Python has several built-in data types categorized into:
A. Numeric Data Types
-
Integer (
int) → Whole numbers
a = 100 # Example of an integer
2. Floating-point (float) → Decimal numbers
b = 10.5 # Example of a float
3. Complex (complex) → Numbers with real and imaginary parts
c = 3 + 5j # Complex number
B. Sequence Data Types
-
String (
str) → Sequence of characters
text = “Python” # String example
2. List (list) → Ordered, mutable collection
numbers = [1, 2, 3, 4, 5] # List example
3. Tuple (tuple) → Ordered, immutable collection
coordinates = (10, 20) # Tuple example
C. Set and Dictionary Data Types
-
Set (
set) → Unordered collection of unique items
unique_numbers = {1, 2, 3, 4} # Set example
2. Dictionary (dict) → Key-value pairs
student = {“name”: “John”, “age”: 25} # Dictionary example
D. Boolean Data Type
-
Boolean (
bool) → RepresentsTrueorFalse
status = True # Boolean example