Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Python Full Stack Synopsis

Uploaded by

parthmahadik455
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Full Stack Synopsis

Uploaded by

parthmahadik455
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PYTHON FULL STACK SYNOPSIS

NAME-PARTH MAHADIK

Topic Date Remark


Install Python ,vscode,Git
Basic syntax and data types
Loops and conditionals
Classes, objects,Functions and
imports
OOP concepts
PYTHON FULL STACK SYNOPSIS

Steps for installing Python on your computer:

Step 1: Download Python

1. Go to the official Python website: https://www.python.org.


2. Click on Downloads and select the appropriate version for your operating system
(Windows, macOS, or Linux).
3. Choose the latest stable release and download the installer.

Step 2: Run the Installer

1. Open the downloaded Python installer file.


2. Check the box that says "Add Python to PATH" (important for running Python from
the command line).
3. Click "Install Now" or choose "Customize Installation" to select additional features.
4. Follow the prompts to complete the installation.

Step 3: Verify Installation

1. Open the command line or terminal:


o On Windows: Open Command Prompt or PowerShell.
o On macOS/Linux: Open the Terminal.
2. Type the command:
3. python --version

or

python3 --version

It should display the version of Python you installed.

Step 4: Install a Code Editor (Optional but Recommended)

1. Download and install Visual Studio Code (VS Code) from


https://code.visualstudio.com.
2. Install the Python extension for VS Code to enhance code editing and debugging.

Step 5: Install Git


PYTHON FULL STACK SYNOPSIS

1. Download Git from https://git-scm.com.


2. Follow the installation instructions for your operating system.

Step 6: Test Python in VS Code

1. Open VS Code and create a new Python file (example.py).


2. Type a simple Python command:
3. print("Hello, Python!")
4. Run the file to check if Python is working correctly.

These steps will set up your environment for Python development.

Variables & Data Types:

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

Python has various data types for different kinds of data:

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

o str: String (e.g., "Hello, World!")

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

Control Flow in Python (if-else and loops):

1. If-Else Statements

Control flow allows decisions in the code based on conditions.

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

Loops are used to execute a block of code repeatedly.

For Loop

Iterates over a sequence (like a list or range).

Syntax

for item in sequence:


# Code block

Example

for num in range(5):


print(num) # Outputs 0, 1, 2, 3, 4
PYTHON FULL STACK SYNOPSIS

While Loop

Repeats as long as a condition is true.

Syntax

while condition:
# Code block

Example

count = 0
while count < 5:
print(count)
count += 1

Break and Continue

 break: Exits the loop immediately.


 continue: Skips the current iteration and moves to the next.

Example

for num in range(5):


if num == 3:
break # Stops the loop when num is 3
print(num)

These control flow structures allow dynamic, decision-making, and repetitive tasks in Python
programs.
PYTHON FULL STACK SYNOPSIS

Control flow

Determines the order in which code is executed in a program. It includes:

1. Conditional Statements (if-else): Make decisions based on conditions.


o Example: If a number is greater than 10, print "High"; otherwise, print "Low."
2. Loops (for, while): Repeat actions until a condition is met.
o Example: A for loop runs for a fixed number of times, and a while loop runs as
long as a condition is true.
3. Break and Continue:
o break: Exits the loop early.
o continue: Skips to the next loop iteration.

Control flow helps control how a program reacts and repeats tasks based on conditions.

Syntax: Control Flow structures in Python:

1. If-Else Statement

Used to make decisions based on conditions.

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

Used to iterate over a sequence (e.g., list, range).

for item in sequence:


# Code to execute for each item in the sequence

Example:

for i in range(5):
print(i)

3. While Loop

Used to repeat code as long as a condition is True.

while condition:
# Code to execute as long as condition is True

Example:

count = 0
while count < 5:
print(count)
count += 1

4. Break and Continue

 break: Exits the loop entirely.


 continue: Skips the current iteration and moves to the next.

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

Functions and Modules in Python

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}!")

greet("Alice") # Output: Hello, Alice!

 Parameters: Variables passed to the function (e.g., name in the example).


 Return: A function can return a value using return (optional).

Function with Return Value


def add(a, b):
return a + b

result = add(3, 4) # result is 7

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 also import specific functions from a module:

from math import sqrt


print(sqrt(16)) # Output: 4.0
Creating Your Own Module

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!")

# In your main program, you can import it


import my_module
my_module.say_hello() # Output: Hello from my module!
PYTHON FULL STACK SYNOPSIS

Object-Oriented Programming (OOP) in Python organizes code into classes and objects to
model real-world entities.

Key Concepts:

1. Class: A blueprint for creating objects (e.g., class Dog:).


2. Object: An instance of a class (e.g., my_dog = Dog()).
3. Attributes: Variables inside a class that store data (e.g., self.name).
4. Methods: Functions inside a class that define behavior (e.g., def bark(self):).
5. Inheritance: Allows a class to inherit methods and attributes from another class (e.g., class
Dog(Animal):).
6. Encapsulation: Bundles data and methods, restricting direct access to some attributes (e.g.,
private attributes with __).
7. Polymorphism: Same method name can have different implementations in different classes
(e.g., speak() in Dog and Bird).

OOP makes code modular, reusable, and easier to maintain.

You might also like