Programming
in Python
Presented By
Mrs.S.Geethamani
Assistant Professor
Dept. of Computer
Application
Sri Ramakrishna College of
AGENDA
Python Basics 01
Standard Data Types 07
Variables in Python 02
Executing Python from the Relational Operators 08
03
Command Line
Logical Operators 09
Editing Python Files 04
Bitwise Operators 10
Reserved Words in Python 05
Simple Input and Output 10
Basic Syntax & Comments 06
Pytho
n
• Python is a widely used, high-level programming language
• It’s open-source and object-oriented.
• Python can be used on a server to create web applications.
• Python can connect to database systems. It can also read and modify files.
• Python can be used to handle big data and perform complex mathematics.
Major Use
of Python
Executing Python
from the Command
Line
https://www.youtube.com/watch?
v=Xw0YGzRZDjU
https://www.google.com/search?
sca_esv=623c97b4ff62327b&rlz=1C1CHBF_enIN1131IN1131&q=Editing+Python+Files&source=lnms&fbs=AIIjpHyXkckd7Il2
1lobbVJc1XW8UWqx1w2L_HS4glko4E1W2IeeIZvHkM4DWoJRZaDIWj-19PEa5EIwXyC_8gqy8sSg0YuGujPNov0Y-
glAntJwAYWTVswxewyWawXPM03mycPjg3k2JTd-
VoWC7VEO86xToZpgRkehh7MfxzCeYMSrLn9ljsvb9NTplw0hbNyBe8_qMGzxAU85Q12Gv6oJ6qRonwIomt-
ZahucJm_0Y_IVRk7zUvc&sa=X&ved=2ahUKEwio8_Xfq5iOAxVfR2wGHaweJGAQ0pQJKAB6BAgSEAE&biw=1366&bih=641&dpr
=1
Editing Python
Files
Get In Touch With
• Reserved words (also known as keywords) are predefined and have
Us special meanings.
• They cannot be used as identifiers (e.g., variable names, function
names).
Here's the list of Python reserved words as of Python 3.10:
PYTHON COMMENTS
TO CREATE A SINGLE AND MULTILINE COMMENT IN PYTHON. SINGLE LINE COMMENT
IN PYTHON USES SYMBOL # AND MULTI LINE COMMENT IN PYTHON USES THREE
SINGLE QUOTES (”’)
CONTROL
STATEMENTS
BUSINESS
CONTROL STATEMENTS: Control Flow and Syntax –
Indenting – if Statement – statements and
expressions- string operations- Boolean
Expressions –while Loop – break and continue – for
Loop.LISTS: List-list slices – list methods – list loop
–sets
P r e s e n t e d b y: O l i v i a
Wilson
Control Flow-Blocks of code that decide
which statements to execute next based
on certain conditions.
Conditional Statement
EG PROGRAMS
marks = 80
result = ""
if marks < 30: OUT PUT:
result = "Failed"
elif marks > 75: Passed with distinction
result = "Passed with
distinction"
else:
result =
"Passed"print(result)
Loops or Iteration Statements
Most of the processes require a
group of instructions to be repeatedly
executed
The continue
Statement
The for loop The while loop The break It skips the
iterates over the repeatedly executes Statement- execution of the
items of any a target statement It terminates the program block and
sequence, such as a as long as a given current loop and returns the control
list, tuple or a boolean expression resumes execution to the beginning of
string is true. at the next the current loop to
statement start the next
iteration.
EG PROGRAMS
x=0 for letter in
while x < 10: "Python":
print("x:", x) # continue when
words = ["one", "two", "three"] i=1 if x == 5: letter is 'h'
for x in words: print("Breaking...") if letter == "h":
while I< 6: continue
print(x) break
print("Current
print(i) x += 1
Letter :", letter)
print("End")
i += 1 OUTPUT:
OUTPUT:
x: 0
x: 0
OUTPUT: x: 1
x: 1
1 x: 2
x: 2
OUT PUT 2 x: 3
x: 3
one 3 x: 4
x: 4
two 4 x: 5
x: 5
three 5 Breaking...
Breaking...
End
End
list methods
Python lists are versatile and come with a variety of
built-in methods for manipulation and inspection.
These methods allow for efficient operations on list
elements.
LIST SLICES
• List slicing is the process
o f a c c e s s i n g a s p e c i fi e d
portion or subset of a list.
• It provides a powerful and
concise way to extract
subsequences, modify
elements, or create copies
of lists.
syntax
list_name[start:stop:step
].
list loop in
python
A list loop in Python means iterating through
each element of a list so you can access or
process them.
EXAMPLE
OUTPUT OUTPUT
OUTPUT
apple Element at index 0: apple
Index: 0, Value: apple
banana Element at index 1:
Index: 1, Value: banana
cherry banana
Element at index 2: cherry Index: 2, Value: cherry
my_list = ["apple", "banana", FOR LOOP WITH FOR LOOP WITH
"cherry"] RANGE(LEN()) ENUMERATE()
my_list = ["apple", "banana", my_list = ["apple", "banana",
for item in my_list: "cherry"] "cherry"]
print(item) for i in range(len(my_list)): for index, value in
print(f"Element at index {i}: enumerate(my_list):
{my_list[i]}") print(f"Index: {index}, Value:
{value}")
SETS IN PYTHON
Sets in Python are an unordered collection data type that stores
unique elements. They are mutable, meaning elements can be
added or removed after creation, but the elements themselves
must be immutable (e.g., numbers, strings, tuples, but not lists
or other sets).
Key characteristics
• Unordered
• Unique elements
• Mutable
• Membership testing
Example
# Create a set
Program
fruits = {"apple", "banana", "cherry", "apple"} # 'apple'
repeated
# Print the set
print(fruits) # Duplicate 'apple' will be removed
# Add a new fruit
fruits.add("orange")
# Check if an item exists OUT PUT
print("banana" in fruits) # True
{'apple', 'banana', 'cherry'}
# Remove a fruit
fruits.remove("banana")
True
{'apple', 'orange', 'cherry'}
# Final set
Common Set
operations