Python Programming
Why to study python?
-Developer
Research Analyst
Devops Engineer
Data Analyst
Data Engineer
Cloud Engineer
ML Ops
Sec Ops
Network Engineer
Python Career
Opportunities
Content
Introduction to Python
Features of Python Programming, Syntax of Python programming,
Python Interactive Shell, Data types, Operators and Types of
Expressions.
Conditional Executions: Boolean Expressions, if Statement, if-else
statement, Compound Boolean Expression, pass statement, Nested
Conditionals.
C: The While Statement, Definite Loops vs Indefinite Loops, for loop
Statement, Nested Loops, While/else and for/else. range() function in
loops.
Python
Python is a popular programming language known for its simplicity and versatility.
Python is the programming with simplicity, powerful libraries, and easy-to-read code.
Whether you’re an experienced programmer or just starting.
Python is a widely used programming language for creating real-world applications. It is
extensively used in:
Data Science
Artificial Intelligence
Automation
Testing
Backend Development
History of Python
Why Python?
Features of Python
Install Python
[Link]
Syntax
Accessing the interactive Python shell
REPL (Read-Eval-Print Loop):
Command Line
IDLE
IPython
Operator
If Statement, else if and else
if(condition):
statement
elif(condition):
statement
else:
Statement
Nested Condition
You can also chain if..else statement with more than one
condition.
if statement can also be checked inside other if statement. This
conditional statement is called a nested if statement.
If (condition1):
# Executes when condition1 is true
if (condition2):
# Executes when condition2 is true
Iterators
An iterator in Python is an object that contains a countable
number of elements that can be iterated upon.
While Loop
while loops execute statements while the condition is True.
If the condition of a loop always evaluates to , the loop
while True
runs continuously, forming an infinite loop. For example,
Python whileloop with break statement
Python whileloop with an else clause
For Loop
for Loop with Python range(): f you do need to iterate over
a sequence of numbers, the built-in function comes in
range()
handy. It generates arithmetic progressions
a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print(i, a[i])
for loops are used when you have a block of code which
you want to repeat a fixed number of times
Match and case:
A Python match-case statement takes an expression and
compares its value to successive patterns given as one or more
case blocks.
match variable_name:
case 'pattern 1' : statement 1
case 'pattern 2' : statement 2
...
case 'pattern n' : statement n
Pass
The Python pass statement is a null operation that does
nothing when executed
Pass is used as placeholder
# Define a function named 'complex_function'
def complex_function():
# Loop through numbers from 0 to 9 (10 iterations)
for i in range(10):
# Check if the current number 'i' is even
if i % 2 == 0:
pass # Placeholder for future logic to handle even numbers
else:
print(i)
`
List
In Python, the list data type is used to store ordered
sequence of elements.
Python lists are ordered collections that can contain
elements of various data types.
Example: lst1=[22,33,”aa”,33.2,23]
Tuple
Tuples are a data structure of the sequence type that store a collection of
data. Python Tuples have these 5 characteristics.
ordered
unchangeable
immutable
allow duplicate value
allow values with multiple data types
Example tp1=(22,”Java”,33.4)
Range
In Python, the range data type comes from
the range() built-in function used to generate a sequence
of numbers
The range() function returns an iterator object generated
by defining start, stop and increment numbers.
range(start, stop, step)
Dictionary
In Python, dictionaries are an unordered collection of key-
value pairs stored as a dict data type. Python
dictionaries are a mappings data type used to store
collections of data.
Creating a dictionary is done adding key, value pairs inside
curly brackets ({}) or using the dict() constructor function.
Example: dist1={id1:name1,id2:name2,…..}
Set
In Python, sets are an unordered collection unique elements (no duplicate values). A
Python set is a mutable object where you can add, remove, or modify elements after
creating it.
Creating a set is done adding comma-separated values inside curly brackets ({}) or
using the set() constructor function.
Python Sets have a multiple characteristics.
Duplicates are not allowed
They can have Multiple data Types
Sets Can’t Be Accessed with the Index
Not Subscriptable
A set is a collection which is unordered, unchangeable*,
and unindexed.
empty_set - an empty set created using set()
empty_dictionary - an empty dictionary created using {}
Frozenset
In Python, the frozenset data type represents an
immutable set.
Creating a frozenset is done using
the frozenset() constructor function. Once created, you
cannot add, remove, or modify elements to the frozenset.
Syntax: frozenset([iterable])
What is Expression in Python?
An expression is a combination of values, variables,
operators, and calls to functions. Expressions need to be
evaluated.
print(2 + 3)
print(len("hello"))