Python Full Stack Synopsis
Python Full Stack Synopsis
NAME-PARTH MAHADIK
or
python3 --version
1. Variables
Definition: Variables store values that can be used and manipulated in a program.
Declaration: In Python, you don’t need to declare the data type of a variable. Simply assign a
value.
name = "John" # String
age = 25 # Integer
height = 5.9 # Float
Variable Naming Rules:
o Must start with a letter or an underscore.
o Cannot start with a number or use special characters.
o Case-sensitive (Name and name are different).
2. Data Types
1. Numeric Types
o int: Whole numbers (e.g., 10, -5)
o float: Decimal numbers (e.g., 3.14, -0.01)
o complex: Complex numbers (e.g., 3+4j)
2. Text Type
PYTHON FULL STACK SYNOPSIS
3. Boolean Type
o bool: True or False
4. Sequence Types
o list: Ordered collection (e.g., [1, 2, 3])
o tuple: Immutable collection (e.g., (4, 5, 6))
o range: Sequence of numbers (e.g., range(5))
5. Set Types
o set: Unordered collection with unique elements (e.g., {1, 2, 3})
6. Mapping Type
o dict: Key-value pairs (e.g., {"name": "Alice", "age": 30})
Example Code
name = "Alice" # String
age = 30 # Integer
height = 5.7 # Float
is_student = True # Boolean
hobbies = ["reading", "traveling", "coding"] # List
Understanding variables and data types is fundamental for writing efficient Python code.
PYTHON FULL STACK SYNOPSIS
1. If-Else Statements
Syntax
if condition:
# Code block if condition is True
elif another_condition:
# Code block if another_condition is True
else:
# Code block if no conditions are True
Example
age = 20
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
2. Loops
For Loop
Syntax
Example
While Loop
Syntax
while condition:
# Code block
Example
count = 0
while count < 5:
print(count)
count += 1
Example
These control flow structures allow dynamic, decision-making, and repetitive tasks in Python
programs.
PYTHON FULL STACK SYNOPSIS
Control flow
Control flow helps control how a program reacts and repeats tasks based on conditions.
1. If-Else Statement
if condition:
# Code to execute if condition is True
elif another_condition:
# Code to execute if another_condition is True
else:
# Code to execute if no conditions are True
Example:
age = 20
if age >= 18:
print("Adult")
else:
print("Minor")
2. For Loop
PYTHON FULL STACK SYNOPSIS
Example:
for i in range(5):
print(i)
3. While Loop
while condition:
# Code to execute as long as condition is True
Example:
count = 0
while count < 5:
print(count)
count += 1
Example:
for i in range(5):
if i == 3:
break # Exits the loop when i is 3
print(i)
for i in range(5):
if i == 3:
continue # Skips when i is 3
print(i)
These are the basic control flow structures for decision-making and repeating tasks in Python.
PYTHON FULL STACK SYNOPSIS
1. Functions
Functions are blocks of reusable code that perform a specific task. They allow you to group code
into a unit that can be called with a single line, making your program more organized and
modular.
Defining a Function
You define a function using the def keyword, followed by the function name and parentheses.
Syntax:
def function_name(parameters):
# Code block
return value # Optional, returns a result
Example:
def greet(name):
print(f"Hello, {name}!")
2. Modules
Modules are files that contain Python code. A module can contain functions, variables, and
classes that can be reused across different programs.
PYTHON FULL STACK SYNOPSIS
Importing Modules
To use a module in your Python code, you use the import statement.
Syntax:
import module_name
Example:
import math
print(math.sqrt(16)) # Output: 4.0
You can create a module by saving your functions and code in a .py file (e.g., my_module.py).
Example (my_module.py):
def say_hello():
print("Hello from my module!")
Object-Oriented Programming (OOP) in Python organizes code into classes and objects to
model real-world entities.
Key Concepts: