SlideShare a Scribd company logo
Copyright 2020 @SquadInfotech, All rights reserved.
PYTHON BASICS
• Jyoti Shukla, SME
Topics
• INTRODUCTION OF PYTHON
• OPERATORS
• CONTROL STATEMENTS
• STRING HANDLING
• COLLECTIONS
• FUNCTIONS
Copyright 2020 @SquadInfotech, All rights reserved.
Introduction
Copyright 2020 @SquadInfotech, All rights reserved.
• What is Python ?
• Features of Python
• Applications of Python
• Who uses Python ?
• Installing Python
• Keywords, Identifiers and Variables
• Data types
What is Python ?
• General purpose high level programming/ scripting
language
• Invented by Guido Van Rossam
• Combination of:
• Functional programming Language from C
• OOPS concept from C++.
• Scripting language from perl and shell script
• Modular programming language from Modula-3.
Copyright 2020 @SquadInfotech, All rights reserved.
Why Python ? (Features)
• Open Source
• Platform Independent
• Portable
• Simple and easy to learn
• Dynamically Typed
• Interpreted Language
• Extensible
• Broad Standard Library
• Supports both function oriented concept and object
oriented concept
Copyright 2020 @SquadInfotech, All rights reserved.
Where to Use ? (Applications)
• Desktop application
• Web applications
• Database Application
• Networking applications
• Games
• Data analysis
• Machine Language
• Artificial Intelligence
Copyright 2020 @SquadInfotech, All rights reserved.
Who Uses Python ?
• Google
• YouTube
• Dropbox
• NASA
• and many more
Copyright 2020 @SquadInfotech, All rights reserved.
Downloading Python
Link: https://www.python.org/downloads/
Copyright 2020 @SquadInfotech, All rights reserved.
Version Timeline
• Python 3.9.5 introduced in Oct 2020
• ..
• Python 3.8 introduced in 14 Oct 2019
• ....
• Python 3.0 introduced in Dec 2008
• Python 2.0 introduced in October 2000
• Python 1.0 introduced in Jan 1994
Python is not backward compatible.
Copyright 2020 @SquadInfotech, All rights reserved.
Variables in Python
⮚ A variable is a Named locations in memory that contain specific
values.
⮚Variables can be almost any name but it makes sense to use
sensible description such as sales_price and not be too long.
⮚A variable is actually a location in memory within the computer.
The program changes the data held in that location by referring to
the variable name.
Reserve Keywords
• There are 33 reserve keywords in python.
'False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for',
'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal',
'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'
Copyright 2020 @SquadInfotech, All rights reserved.
Identifiers
• Only A-Z, a-z and 0-9 can be used to create an identifier
but shouldn't start with a digit.
• Identifiers are Case Sensitive.
• Reserve Keywords are not allowed as Identifiers.
• No long limit.
• Only underscore ‘_’, a special character is allowed in an
identifier.
• Eg: counter, counter1, arr_count etc
Copyright 2020 @SquadInfotech, All rights reserved.
Variables in Python
Data types
• Int
• Float
• Complex
• Bool
• Str
• Bytes
• Bytearray
• Range
• List
• Tuple
• Set
• Frozenset
• Dict
• None
Copyright 2020 @SquadInfotech, All rights reserved.
Type casting/type
conversion/Type coersion
• Function for type casting
• int()
• float()
• complex()
• bool()
• str()
Copyright 2020 @SquadInfotech, All rights reserved.
Operators
Copyright 2020 @SquadInfotech, All rights reserved.
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
Arithmetic Operators
• + Addition (x + y)
• - Subtraction (x – y)
• * Multiplication (x * y)
• / Division (x / y)
• % Modulus (x % y)
• ** Exponentiation (x ** y)
• // Floor division (x // y)
Copyright 2020 @SquadInfotech, All rights reserved.
Assignment Operators
• = x = 5 (x = 5)
• += x+=5 (x = x + 5)
• -= x -= 5 (x = x – 5)
• *= x *= 5 (x = x * 5)
• /= x /= 5 (x = x / 5)
• %= x %= 5 (x = x % 5)
• //= x //= 5 (x = x // 5)
• **= x **= 5 (x = x ** 5)
• &= (x &= 5) (x = x & 5)
• |= x |= 5 (x = x | 5)
^= x ^= 5 (x = x ^ 5)
Copyright 2020 @SquadInfotech, All rights reserved.
Comparison operators
• > (Greater than)
• < (Lesser than)
• == (Equal to )
• != (Not equal to)
• >= (Greater than or equal to)
• <= (Less than or equal to)
Copyright 2020 @SquadInfotech, All rights reserved.
Logical Operators
and := if both values are true then only result is true
Or:=True if either of the operands is true
Not:= complement
Copyright 2020 @SquadInfotech, All rights reserved.
Or operator Evaluates True when Any one
Condition is Evaluated as True.
Bitwise Operators
• & Bitwise AND
• |Bitwise OR
• ~Bitwise NO
• ^Bitwise XOR
• >>Bitwise right shift
• <<Bitwise left shift
Copyright 2020 @SquadInfotech, All rights reserved.
Membership Operators
• are used to test whether a value or variable is found in a
sequence (string, list, tuple, set and dictionary).
• In:=True if value/variable is found in the sequence
• Not in:=True if value/variable is not found in the sequence
Copyright 2020 @SquadInfotech, All rights reserved.
Identity operators
• They are used to check if two values (or variables) are
located on the same part of the memory. Two variables
that are equal does not imply that they are identical.
• is :=True if the operands are identical (refer to the same
object)
• is not := True if the operands are not identical (do not
refer to the same object)
Copyright 2020 @SquadInfotech, All rights reserved.
Control Statements
Copyright 2020 @SquadInfotech, All rights reserved.
Flow control
Copyright 2020 @SquadInfotech, All rights reserved.
1.IF condition
If…Else (Conditional Statments)
Syntax:
if condition:
#code
else:
#code
Example (Odd Even)
num= int(input("Enter the
number to check: "))
if num%2 is 0:
print("even number")
else:
print("odd number")
Copyright 2020 @SquadInfotech, All rights reserved.
2. IF ELSE Condition
Divisibility
→ A number is exactly divisible by some other number if it gives 0 as
remainder. To check if a number is exactly divisible by some number we
need to test if it leaves 0 as remainder or not.
→ In Programming, We a modulo operator %, that evaluates remainder
on division of two operands. You can use this to check if a number is
exactly divisible by some number or not.
→ For example - if(8 % 2), if the given expression evaluates 0, then 8 is
exactly divisible by 2.
Step by step descriptive logic to check whether a number is divisible by 5
and 11 or not.
→ Input a number from user. Store it in some variable say num.
→ To check divisibility with 5,
check if(num % 5 == 0) then num is divisible by 5.
→ To check divisibility with 11,
check if(num % 11 == 0) then num is divisible by 11.
→ Now combine the above two conditions using logical AND operator.
→ To check divisibility with 5 and 11 both,
check if((num % 5 == 0) and (num % 11 == 0)),
then number is divisible by both 5 and 11.
Write an algorithm to check weather the number is even or odd
For a number to an even it should be divisible by 2 and if it is
not, it’s odd.
Let n input
←
If ( n % 2 == 0 )
Then print n is even
Else
Print n is odd
Nested If…. else
Syntax
if condition:
#code
if condition:
#code
else:
#code
else:
#code
Example
per=int(input("Enter your
percentage: "))
if per >= 60:
exp= int(input("Enter the number
of experience: "))
if exp >= 2:
print("eligible for job")
else:
print("not eligible for job")
else:
print("not qualified“)
Copyright 2020 @SquadInfotech, All rights reserved.
4. Nested IF Condition
Check weather the year is leap or not
Constraints-:
1. N div by 400 leap year
→
2. N div by 4 , N not div by 100 leap
→
let N ← input
if (n % 4 == 0)
if (n % 100 == 0)
if (n % 400 == 0)
print n
is leap year
else
print n
is not a leap year
else
print n i leap year
else
print n is not leap year
FlowChart of Leap year
Ladder If…. else
Syntax
• Example
if condition:
#code
elif condition:
#code
elif condition:
#code
else:
#code
per= int(input("Enter your
percentage: “))
if per >= 90:
print("A grade")
elif per >=70 and per<90:
print("B grade")
elif per >=50 and per<70:
print(“C grade")
else:
print(“Be positive, Work hard")
Copyright 2020 @SquadInfotech, All rights reserved.
3. ELSE IF Ladder
Flowchart to given a marks print grade
Constraints -:
75 & above -: A grade
60-74 -: B grade
35-59 -: C grade
Below 35 -: Fail
Let mark <- input
If ( mark>=75 )
Then print A grade
Elseif ( mark>=60 and mark<=74 )
Then print B grade
Elseif ( mark>=35 and mark<=59 )
Then print C grade
Else
Print Fail
Flowchart to given a marks print grade
Leap year through if - else statement
Constraints-:
1. N div by 400 leap year
→
2. N div by 4 , N not div by 100 leap
→
Let N ← input
If ( N % 400==0 or (N% 4==0 and N % 100 !=0)
Then print N is a leap year
Else
Print N is not a leap year
FlowChart of Leap year
Leap year through if-elseif-else statement
Constraints-:
1. N div by 400 leap year
→
2. N div by 4 , N not div by 100 leap
→
let N ← input
If (N% 400 ==0)
then print N is a Leap year
Elseif (N % 4==0 and N % 100!=0)
then print N is a leap year
Else
print n is not leap year
FlowChart of Leap year with if elseif else
Loops (Iterative statements)
while (condition):
#code
num=int(input(“Enter a number:
"))
counter=1
print(“Below are even numbers: ”)
while counter<=num:
if counter%2==0:
print(counter)
counter+=1
Syntax
Example
Copyright 2020 @SquadInfotech, All rights reserved.
For loop
Syntax
for counter in range (lower
limit,
upper limit,
[increment factor]):
#code
Example
for i in range(1,5):
# default increment is1
print(i)
for i in range(5,0,-1):
#decrementing by -1
print(i, end=“ ”)
Copyright 2020 @SquadInfotech, All rights reserved.
String Handling
Copyright 2020 @SquadInfotech, All rights reserved.
Introduction
• Strings are arrays of bytes representing Unicode
characters.
• Python does not have a character data type.
• A single character is simply a string with a length of 1.
• Square brackets can be used to access elements of the
string.
• Strings can be created using single, double or even triple
quotes.
Copyright 2020 @SquadInfotech, All rights reserved.
Indexing
Copyright 2020 @SquadInfotech, All rights reserved.
Creating Strings
• String in single quotes cannot hold any other single quoted
character in it because the compiler won’t recognize where
to start and end the string.
• To overcome this error, double quotes is preferred, because
it helps in creation of Strings with single quotes in them.
• For strings which contain Double quoted words in them, use
of triple quotes is suggested. Along with this, triple quotes
also allow the creation of multiline strings.
Copyright 2020 @SquadInfotech, All rights reserved.
Example of strings
Single Quote
• Double Quoted string has a
Single Quote
# Creation of String
# with single Quotes
str1 = 'Welcome to the Coder Technologies‘
print(str1)
# Creating a String
# with double Quotes
str2 = "I'm learning python“
print(str2)
Copyright 2020 @SquadInfotech, All rights reserved.
Example of strings (cont..)
Triple Quotes
• Multiline with Triple
quotes
# Creating a String
# with triple Quotes
str3 = ‘’’I'm learning python and I’m lovin’ it’’’
print(str3)
# Creating multiline
# strings
str4 = '''hi
how are you?
This lockdown is so boring!
'''
print(str4)
Copyright 2020 @SquadInfotech, All rights reserved.
String Operations
• Access characters within a string
• Concatenating
• Iterating
• Formatting
• Built-in string methods
Copyright 2020 @SquadInfotech, All rights reserved.
Collections
Copyright 2020 @SquadInfotech, All rights reserved.
Python Collections
There are four collection data types:
• List: Ordered and changeable. Allows duplicate members.
• Tuple: Ordered and unchangeable. Allows duplicate
members.
• Set: Unordered and un-indexed. No duplicate members.
• Dictionary: Unordered, changeable and indexed. No
duplicate members.
Copyright 2020 @SquadInfotech, All rights reserved.

More Related Content

Similar to PYTHON BASICS CODING LANGUAGE GO TO.pptx (20)

PPT
python operators.ppt
ErnieAcuna
 
PDF
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
PPT
Introduction to Python Language and Data Types
Ravi Shankar
 
PPT
introduction to python in english presentation file
RujanTimsina1
 
PPTX
Python4HPC.pptx
priyam737974
 
PPTX
Python4HPC.pptx
Sonam Mittal
 
PPTX
Introduction to vrevr rv4 rvr r r r u r a Python.pptx
sahilurrahemankhan
 
PPTX
Python details for beginners and for students
ssuser083eed1
 
PDF
Data Handling.pdf
MILANOP1
 
PDF
Python Programming
Sreedhar Chowdam
 
PPT
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
PDF
computer science CLASS 11 AND 12 SYLLABUS.pdf
SomnathSaha63
 
PDF
1_Python Basics.pdf
MaheshGour5
 
PPTX
made it easy: python quick reference for beginners
SumanMadan4
 
PDF
Introduction to Python
Mohammed Sikander
 
PPTX
Keep it Stupidly Simple Introduce Python
SushJalai
 
PPT
Py-Slides-2 (1).ppt
KalaiVani395886
 
PPT
Py-Slides-2.ppt
TejaValmiki
 
PPT
Py-Slides-2.ppt
AllanGuevarra1
 
python operators.ppt
ErnieAcuna
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Introduction to Python Language and Data Types
Ravi Shankar
 
introduction to python in english presentation file
RujanTimsina1
 
Python4HPC.pptx
priyam737974
 
Python4HPC.pptx
Sonam Mittal
 
Introduction to vrevr rv4 rvr r r r u r a Python.pptx
sahilurrahemankhan
 
Python details for beginners and for students
ssuser083eed1
 
Data Handling.pdf
MILANOP1
 
Python Programming
Sreedhar Chowdam
 
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
computer science CLASS 11 AND 12 SYLLABUS.pdf
SomnathSaha63
 
1_Python Basics.pdf
MaheshGour5
 
made it easy: python quick reference for beginners
SumanMadan4
 
Introduction to Python
Mohammed Sikander
 
Keep it Stupidly Simple Introduce Python
SushJalai
 
Py-Slides-2 (1).ppt
KalaiVani395886
 
Py-Slides-2.ppt
TejaValmiki
 
Py-Slides-2.ppt
AllanGuevarra1
 

Recently uploaded (20)

PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Ad

PYTHON BASICS CODING LANGUAGE GO TO.pptx

  • 1. Copyright 2020 @SquadInfotech, All rights reserved. PYTHON BASICS • Jyoti Shukla, SME
  • 2. Topics • INTRODUCTION OF PYTHON • OPERATORS • CONTROL STATEMENTS • STRING HANDLING • COLLECTIONS • FUNCTIONS Copyright 2020 @SquadInfotech, All rights reserved.
  • 3. Introduction Copyright 2020 @SquadInfotech, All rights reserved. • What is Python ? • Features of Python • Applications of Python • Who uses Python ? • Installing Python • Keywords, Identifiers and Variables • Data types
  • 4. What is Python ? • General purpose high level programming/ scripting language • Invented by Guido Van Rossam • Combination of: • Functional programming Language from C • OOPS concept from C++. • Scripting language from perl and shell script • Modular programming language from Modula-3. Copyright 2020 @SquadInfotech, All rights reserved.
  • 5. Why Python ? (Features) • Open Source • Platform Independent • Portable • Simple and easy to learn • Dynamically Typed • Interpreted Language • Extensible • Broad Standard Library • Supports both function oriented concept and object oriented concept Copyright 2020 @SquadInfotech, All rights reserved.
  • 6. Where to Use ? (Applications) • Desktop application • Web applications • Database Application • Networking applications • Games • Data analysis • Machine Language • Artificial Intelligence Copyright 2020 @SquadInfotech, All rights reserved.
  • 7. Who Uses Python ? • Google • YouTube • Dropbox • NASA • and many more Copyright 2020 @SquadInfotech, All rights reserved.
  • 9. Version Timeline • Python 3.9.5 introduced in Oct 2020 • .. • Python 3.8 introduced in 14 Oct 2019 • .... • Python 3.0 introduced in Dec 2008 • Python 2.0 introduced in October 2000 • Python 1.0 introduced in Jan 1994 Python is not backward compatible. Copyright 2020 @SquadInfotech, All rights reserved.
  • 10. Variables in Python ⮚ A variable is a Named locations in memory that contain specific values. ⮚Variables can be almost any name but it makes sense to use sensible description such as sales_price and not be too long. ⮚A variable is actually a location in memory within the computer. The program changes the data held in that location by referring to the variable name.
  • 11. Reserve Keywords • There are 33 reserve keywords in python. 'False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield' Copyright 2020 @SquadInfotech, All rights reserved.
  • 12. Identifiers • Only A-Z, a-z and 0-9 can be used to create an identifier but shouldn't start with a digit. • Identifiers are Case Sensitive. • Reserve Keywords are not allowed as Identifiers. • No long limit. • Only underscore ‘_’, a special character is allowed in an identifier. • Eg: counter, counter1, arr_count etc Copyright 2020 @SquadInfotech, All rights reserved.
  • 14. Data types • Int • Float • Complex • Bool • Str • Bytes • Bytearray • Range • List • Tuple • Set • Frozenset • Dict • None Copyright 2020 @SquadInfotech, All rights reserved.
  • 15. Type casting/type conversion/Type coersion • Function for type casting • int() • float() • complex() • bool() • str() Copyright 2020 @SquadInfotech, All rights reserved.
  • 16. Operators Copyright 2020 @SquadInfotech, All rights reserved. • Arithmetic operators • Assignment operators • Comparison operators • Logical operators • Identity operators • Membership operators • Bitwise operators
  • 17. Arithmetic Operators • + Addition (x + y) • - Subtraction (x – y) • * Multiplication (x * y) • / Division (x / y) • % Modulus (x % y) • ** Exponentiation (x ** y) • // Floor division (x // y) Copyright 2020 @SquadInfotech, All rights reserved.
  • 18. Assignment Operators • = x = 5 (x = 5) • += x+=5 (x = x + 5) • -= x -= 5 (x = x – 5) • *= x *= 5 (x = x * 5) • /= x /= 5 (x = x / 5) • %= x %= 5 (x = x % 5) • //= x //= 5 (x = x // 5) • **= x **= 5 (x = x ** 5) • &= (x &= 5) (x = x & 5) • |= x |= 5 (x = x | 5) ^= x ^= 5 (x = x ^ 5) Copyright 2020 @SquadInfotech, All rights reserved.
  • 19. Comparison operators • > (Greater than) • < (Lesser than) • == (Equal to ) • != (Not equal to) • >= (Greater than or equal to) • <= (Less than or equal to) Copyright 2020 @SquadInfotech, All rights reserved.
  • 20. Logical Operators and := if both values are true then only result is true Or:=True if either of the operands is true Not:= complement Copyright 2020 @SquadInfotech, All rights reserved.
  • 21. Or operator Evaluates True when Any one Condition is Evaluated as True.
  • 22. Bitwise Operators • & Bitwise AND • |Bitwise OR • ~Bitwise NO • ^Bitwise XOR • >>Bitwise right shift • <<Bitwise left shift Copyright 2020 @SquadInfotech, All rights reserved.
  • 23. Membership Operators • are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary). • In:=True if value/variable is found in the sequence • Not in:=True if value/variable is not found in the sequence Copyright 2020 @SquadInfotech, All rights reserved.
  • 24. Identity operators • They are used to check if two values (or variables) are located on the same part of the memory. Two variables that are equal does not imply that they are identical. • is :=True if the operands are identical (refer to the same object) • is not := True if the operands are not identical (do not refer to the same object) Copyright 2020 @SquadInfotech, All rights reserved.
  • 25. Control Statements Copyright 2020 @SquadInfotech, All rights reserved.
  • 26. Flow control Copyright 2020 @SquadInfotech, All rights reserved.
  • 28. If…Else (Conditional Statments) Syntax: if condition: #code else: #code Example (Odd Even) num= int(input("Enter the number to check: ")) if num%2 is 0: print("even number") else: print("odd number") Copyright 2020 @SquadInfotech, All rights reserved.
  • 29. 2. IF ELSE Condition
  • 30. Divisibility → A number is exactly divisible by some other number if it gives 0 as remainder. To check if a number is exactly divisible by some number we need to test if it leaves 0 as remainder or not. → In Programming, We a modulo operator %, that evaluates remainder on division of two operands. You can use this to check if a number is exactly divisible by some number or not. → For example - if(8 % 2), if the given expression evaluates 0, then 8 is exactly divisible by 2.
  • 31. Step by step descriptive logic to check whether a number is divisible by 5 and 11 or not. → Input a number from user. Store it in some variable say num. → To check divisibility with 5, check if(num % 5 == 0) then num is divisible by 5. → To check divisibility with 11, check if(num % 11 == 0) then num is divisible by 11. → Now combine the above two conditions using logical AND operator. → To check divisibility with 5 and 11 both, check if((num % 5 == 0) and (num % 11 == 0)), then number is divisible by both 5 and 11.
  • 32. Write an algorithm to check weather the number is even or odd For a number to an even it should be divisible by 2 and if it is not, it’s odd. Let n input ← If ( n % 2 == 0 ) Then print n is even Else Print n is odd
  • 33. Nested If…. else Syntax if condition: #code if condition: #code else: #code else: #code Example per=int(input("Enter your percentage: ")) if per >= 60: exp= int(input("Enter the number of experience: ")) if exp >= 2: print("eligible for job") else: print("not eligible for job") else: print("not qualified“) Copyright 2020 @SquadInfotech, All rights reserved.
  • 34. 4. Nested IF Condition
  • 35. Check weather the year is leap or not Constraints-: 1. N div by 400 leap year → 2. N div by 4 , N not div by 100 leap → let N ← input if (n % 4 == 0) if (n % 100 == 0) if (n % 400 == 0) print n is leap year else print n is not a leap year else print n i leap year else print n is not leap year
  • 37. Ladder If…. else Syntax • Example if condition: #code elif condition: #code elif condition: #code else: #code per= int(input("Enter your percentage: “)) if per >= 90: print("A grade") elif per >=70 and per<90: print("B grade") elif per >=50 and per<70: print(“C grade") else: print(“Be positive, Work hard") Copyright 2020 @SquadInfotech, All rights reserved.
  • 38. 3. ELSE IF Ladder
  • 39. Flowchart to given a marks print grade Constraints -: 75 & above -: A grade 60-74 -: B grade 35-59 -: C grade Below 35 -: Fail Let mark <- input If ( mark>=75 ) Then print A grade Elseif ( mark>=60 and mark<=74 ) Then print B grade Elseif ( mark>=35 and mark<=59 ) Then print C grade Else Print Fail
  • 40. Flowchart to given a marks print grade
  • 41. Leap year through if - else statement Constraints-: 1. N div by 400 leap year → 2. N div by 4 , N not div by 100 leap → Let N ← input If ( N % 400==0 or (N% 4==0 and N % 100 !=0) Then print N is a leap year Else Print N is not a leap year
  • 43. Leap year through if-elseif-else statement Constraints-: 1. N div by 400 leap year → 2. N div by 4 , N not div by 100 leap → let N ← input If (N% 400 ==0) then print N is a Leap year Elseif (N % 4==0 and N % 100!=0) then print N is a leap year Else print n is not leap year
  • 44. FlowChart of Leap year with if elseif else
  • 45. Loops (Iterative statements) while (condition): #code num=int(input(“Enter a number: ")) counter=1 print(“Below are even numbers: ”) while counter<=num: if counter%2==0: print(counter) counter+=1 Syntax Example Copyright 2020 @SquadInfotech, All rights reserved.
  • 46. For loop Syntax for counter in range (lower limit, upper limit, [increment factor]): #code Example for i in range(1,5): # default increment is1 print(i) for i in range(5,0,-1): #decrementing by -1 print(i, end=“ ”) Copyright 2020 @SquadInfotech, All rights reserved.
  • 47. String Handling Copyright 2020 @SquadInfotech, All rights reserved.
  • 48. Introduction • Strings are arrays of bytes representing Unicode characters. • Python does not have a character data type. • A single character is simply a string with a length of 1. • Square brackets can be used to access elements of the string. • Strings can be created using single, double or even triple quotes. Copyright 2020 @SquadInfotech, All rights reserved.
  • 50. Creating Strings • String in single quotes cannot hold any other single quoted character in it because the compiler won’t recognize where to start and end the string. • To overcome this error, double quotes is preferred, because it helps in creation of Strings with single quotes in them. • For strings which contain Double quoted words in them, use of triple quotes is suggested. Along with this, triple quotes also allow the creation of multiline strings. Copyright 2020 @SquadInfotech, All rights reserved.
  • 51. Example of strings Single Quote • Double Quoted string has a Single Quote # Creation of String # with single Quotes str1 = 'Welcome to the Coder Technologies‘ print(str1) # Creating a String # with double Quotes str2 = "I'm learning python“ print(str2) Copyright 2020 @SquadInfotech, All rights reserved.
  • 52. Example of strings (cont..) Triple Quotes • Multiline with Triple quotes # Creating a String # with triple Quotes str3 = ‘’’I'm learning python and I’m lovin’ it’’’ print(str3) # Creating multiline # strings str4 = '''hi how are you? This lockdown is so boring! ''' print(str4) Copyright 2020 @SquadInfotech, All rights reserved.
  • 53. String Operations • Access characters within a string • Concatenating • Iterating • Formatting • Built-in string methods Copyright 2020 @SquadInfotech, All rights reserved.
  • 55. Python Collections There are four collection data types: • List: Ordered and changeable. Allows duplicate members. • Tuple: Ordered and unchangeable. Allows duplicate members. • Set: Unordered and un-indexed. No duplicate members. • Dictionary: Unordered, changeable and indexed. No duplicate members. Copyright 2020 @SquadInfotech, All rights reserved.