PYTHON (1)
PYTHON (1)
INTRODUCTION
E.g.: In C
• Simple and easy-to-learn #include<stdio.h>
#include<conio.h>
• Easy to read and void main()
{
understand printf(“Hello World”);
getch();
}
• Interpreted and interactive
In python
• Free and Open Source print(“Hello World”)
• Object-Oriented Language
• Portable
• Multi-Platform
• Easy to Debug
PYTHON USED FOR
1. Web development
2. Machine learning
3. Data analysis/visualization
4. Web scrapping
5. Game development
6. Desktop app etc…
HISTORY
Netherland.
ABC language
Modula-3
Software Engineer
Web Developer
Data Analyst
Data Scientist
Software Developer
Machine Learning Engineer
SITES
Instagram
YouTube
Google
IDENTIFIERS
print("Hello, World!")
Inline Comments:
# written in
print("Hello, World!")
• Alternatively, use a multiline string (triple quotes) to create
a comment block.
Eg: """
This is a comment written in
more than just one line
"""
print("Hello, World!")
QUOTES
Conditional statements, allow you to execute different blocks of code based on certain
conditions.
if statement
if-else statement
If-elif-else statement
if statement
The if statement is used to execute a block of code if a
specified condition is true. If the condition evaluates to false,
the block of code is skipped.
if condition :
# code to be executed
If-else statement
The if-else statement allows you to execute one block of code if
a condition is true, and a different block of code if the condition
is false.
if condition:
# code to be executed
else:
#code to be executed
If-elif-else Statement
The if-elif-else statement allows you to check multiple conditions and
execute different blocks of code based on which condition is true. The elif
keyword stands for "else if".
if expression 1:
# code to be executed
elif expression 2:
# code to be executed
elif expression 3:
# code to be executed
else:
# code to be executed
INDENTATION IN PYTHON
• for loop
• while loop
for loop
for loops are used to iterate over a sequence of
items
while condition:
# Code block to be repeated
Loop Control Statements
‘break’: Terminates the loop prematurely when a
certain condition is met.
‘continue’: Skips the current iteration of the loop
and proceeds to the next iteration.
‘pass’(placeholder): When the pass statement is
executed , nothing happens.
DATA TYPES
Immutable
• Integer
• Float
• Boolean
• String
• Tuple
Mutable
• List
• Set
• Dictionary
FUNCTIONS
A group of related statements to perform a specific task is known as a
function.
Functions help to break the program into smaller units.
Functions avoid repetition and enhance code reusability.
i) Built-in functions
ii) User-defined functions
Built-in Functions:-
These functions are provided by Python itself and are readily available for use
without the need for additional import statements.
Examples include print(), len(), range(), max(), min(), etc.
print("Hello, world!")
User-defined Functions:-
User-defined functions are created by the programmer to perform
specific tasks or operations.
def greet():
print("Hello, welcome!")
greet()
Defining Functions:-
You can define a function in Python using the ‘def’ keyword followed by the function
name and parameters enclosed in parentheses. The function body is then indented.
Calling Functions:-
To execute a function, simply write its name followed by parentheses.
Function Parameters:-
Functions can accept parameters, which are values passed to the function when it's called.
Return Statement:-
Functions can return values using the return statement.
Recursion:-
A defined function can call itself.
Map Functions:-
Works as an iterator to return a result after applying a function to
every item of an iterable.
map(function, iterables)
Filter Functions:-
Used to filter elements from an iterable based on a
given condition.
filter(function, iterables)
Lambda Functions:-
Lambda functions, also known as anonymous
functions.
Its a small, unnamed functions that are defined using
the lambda keyword.
Function = lambda args:expression
OOPS CONCEPT
• Python is a multi-paradigm programming language.(approach to solve problems)
• Procedural Oriented Programming (POP)
• large programs are divided into smaller programs known as functions.
• no data security.
• Object Oriented Programming (OOP)
• Solve problem by using objects
• Object and class are the main components
Object Oriented Programming
OOPs allow user to create their own objects, i.e, attributes and methods.
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation