SlideShare a Scribd company logo
Here in this class we will deal with Network
Automation with the help of Python
FOR CLASSES CALL +91-9790901210
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
Python 3 for Network Engineers
Basics of Python
• Understand a point, Coding is not all about how much you know, its
all about what are the stuffs you can based on how much you know.
• Lets get started quickly. We will have 2 sessions in this course.
• 1st session will introduce the possible commands and explanation
• 2nd session we will jump into Python for Network Engineers
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
What Python can do
• We can create games, software’s etc
• However we will focus on Python feature that’s helping the network
engineer to make our job easy.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
Boolean
comparison
Python
Programming
Overview
• There are 8 comparison operators in python.
• All have same priority.
• They can chained arbitrarily like x<y<=z is equivalent to x<y and y<=z
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
Operation Meaning
< Strictly less than
<= Less than or equals to
> Strictly greater than
>= Greater than or equals to
== Equals
!= Not equals
Is Object identity
Is not Negated object identity
Comparison operator
You can below commands to check
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
x=7 # here you are assigning
a value to the variable x
x==5 #comparig if x is equal
to 5
x==6
x==8
x<7
x>8
x<9
x=7
x
7
x<10
True
x<5
False
x==9
False
x==10
False
x>=3
True
x<8
True
x!=7
False
Command
Output
x>3 and x>4
True
x>1 or x>100
True
Using “and” “or”
Boolean operators AND , OR
Below table you can use
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
>>>True and True
True
>>>True and False
False
>>>True or False
True
>>>False or False
False
>>>Boo1=True
>>>Boo2=False
>>>Boo1 and Boo2
True
>>>Boo1=True
>>>Boo1 not
False
>>>’Network’==‘network’
False
>>>’Network’==‘Network’
True
Lists with Boolean
We can check if the List is empty or not.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
>>>List2=['Vishnu','Vardhan']
>>>List2
['Vishnu', 'Vardhan']
>>>if List2:
... print("The list is not empty")
... else:
... print("The list is empty")
...
The list is not empty
Creating a List using Split
You can chop a string to create a list.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
>>>Name="Vishnu/Vardhan/Maddy/Rock"
>>>Name
'Vishnu/Vardhan/Maddy/Rock'
>>>Name.split("/")
['Vishnu', 'Vardhan', 'Maddy', 'Rock']
>>>Name="vishnu Vardhan"
>>>Name.split(" ")
['vishnu', 'Vardhan']
>>>List1=Name.split(" ")
>>>List1
['vishnu', 'Vardhan']
>>>List1[1]
'Vardhan'
>>>List1[0]
'vishnu'
>>>Name[0]
'v'
Lists Vs Tuples
Tuples are Immutable meaning once set the values cannot be changed.
They collet some heterogeneous values.
Lists are Mutable meaning these values can be changed
They collect only homogeneous values.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
Lists in Lists
We can use Lists inside a list.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
>>>List1=['R1','R2','R3']
>>>List2=['S1','S2','S3']
>>>List1
['R1', 'R2', 'R3']
>>>List2
['S1', 'S2', 'S3']
>>>List3=[List1,List2]
>>>List3
[['R1', 'R2', 'R3'], ['S1', 'S2', 'S3']]
>>>List3[0][1] #Using this you can check 1st list
second value
'R2'
>>>List3[1][2]
'S3
Extending a lists
We can extend a list using .extend command like below
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
>>>List1
['R1', 'R2', 'R3']
>>>List1.append("R4")
>>>List1
['R1', 'R2', 'R3', 'R4']
>>>List2
['S1', 'S2', 'S3']
>>>List1.extend(List2)
List1
['R10', 'R2', 'R3', 'R4', 'S1', 'S2',
'S3']
>>>Router_list1=['R1', 'R2', 'R3', 'R4']
>>>Router_list2=['R5','R6','R7','R8']
>>>Router_list2 += Router_list2
>>>Router_list1
['R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7',
'R8']
Other stuffs we can do with Lists
Below link can help you to find a reference.
https://docs.python.org/2/tutorial/datastructures.html
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
>>>Router_list1=['R1', 'R2', 'R3', 'R4']
>>>Router_list1.insert(0,"R0")
['R0','R1', 'R2', 'R3', 'R4']
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210

More Related Content

Similar to 2. basics of python

Computer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
RedenOriola
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
Giovanni Della Lunga
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfzJoshua Thijssen
 
Python material
Python materialPython material
Python material
Ruchika Sinha
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 
Python
PythonPython
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Arnaud Joly
 
Mrs. Noland's Binary System ppt
Mrs. Noland's Binary System pptMrs. Noland's Binary System ppt
Mrs. Noland's Binary System ppt
dsparone
 
Magic 8 ball prorgramming or structure is fun
Magic 8 ball prorgramming or structure is funMagic 8 ball prorgramming or structure is fun
Magic 8 ball prorgramming or structure is fun
geekinlibrariansclothing
 
Python001 training course_mumbai
Python001 training course_mumbaiPython001 training course_mumbai
Python001 training course_mumbai
vibrantuser
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
Marc Gouw
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
Wim Godden
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 

Similar to 2. basics of python (17)

Computer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .pptComputer 10 Quarter 3 Lesson .ppt
Computer 10 Quarter 3 Lesson .ppt
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Python material
Python materialPython material
Python material
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Sql full tutorial
Sql full tutorialSql full tutorial
Sql full tutorial
 
Python
PythonPython
Python
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Mrs. Noland's Binary System ppt
Mrs. Noland's Binary System pptMrs. Noland's Binary System ppt
Mrs. Noland's Binary System ppt
 
Magic 8 ball prorgramming or structure is fun
Magic 8 ball prorgramming or structure is funMagic 8 ball prorgramming or structure is fun
Magic 8 ball prorgramming or structure is fun
 
Python001 training course_mumbai
Python001 training course_mumbaiPython001 training course_mumbai
Python001 training course_mumbai
 
Python study material
Python study materialPython study material
Python study material
 
Python course
Python coursePython course
Python course
 
Class 1: Welcome to programming
Class 1: Welcome to programmingClass 1: Welcome to programming
Class 1: Welcome to programming
 
Beyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the codeBeyond PHP - it's not (just) about the code
Beyond PHP - it's not (just) about the code
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 

More from Vishnu Vardhan

Chapter 25. implementing i pv6 routing
Chapter 25. implementing i pv6 routingChapter 25. implementing i pv6 routing
Chapter 25. implementing i pv6 routing
Vishnu Vardhan
 
5. configuring multiple switch with files
5. configuring multiple switch with files5. configuring multiple switch with files
5. configuring multiple switch with files
Vishnu Vardhan
 
Ospf
OspfOspf
Chapter 4. using the command line interface
Chapter 4. using the command line interfaceChapter 4. using the command line interface
Chapter 4. using the command line interface
Vishnu Vardhan
 
Chapter 3.1 subnetting
Chapter 3.1 subnetting Chapter 3.1 subnetting
Chapter 3.1 subnetting
Vishnu Vardhan
 
Chapter 3. fundamentals of wan and ip routing
Chapter 3. fundamentals of wan and ip routingChapter 3. fundamentals of wan and ip routing
Chapter 3. fundamentals of wan and ip routing
Vishnu Vardhan
 
Chapter 2. fundamentals of ethernet la ns
Chapter 2. fundamentals of ethernet la nsChapter 2. fundamentals of ethernet la ns
Chapter 2. fundamentals of ethernet la ns
Vishnu Vardhan
 
Chapter 1.2 osi layer
Chapter 1.2 osi layerChapter 1.2 osi layer
Chapter 1.2 osi layer
Vishnu Vardhan
 
Chapter 1. introduction to tcpip networking
Chapter 1. introduction to tcpip networkingChapter 1. introduction to tcpip networking
Chapter 1. introduction to tcpip networking
Vishnu Vardhan
 

More from Vishnu Vardhan (9)

Chapter 25. implementing i pv6 routing
Chapter 25. implementing i pv6 routingChapter 25. implementing i pv6 routing
Chapter 25. implementing i pv6 routing
 
5. configuring multiple switch with files
5. configuring multiple switch with files5. configuring multiple switch with files
5. configuring multiple switch with files
 
Ospf
OspfOspf
Ospf
 
Chapter 4. using the command line interface
Chapter 4. using the command line interfaceChapter 4. using the command line interface
Chapter 4. using the command line interface
 
Chapter 3.1 subnetting
Chapter 3.1 subnetting Chapter 3.1 subnetting
Chapter 3.1 subnetting
 
Chapter 3. fundamentals of wan and ip routing
Chapter 3. fundamentals of wan and ip routingChapter 3. fundamentals of wan and ip routing
Chapter 3. fundamentals of wan and ip routing
 
Chapter 2. fundamentals of ethernet la ns
Chapter 2. fundamentals of ethernet la nsChapter 2. fundamentals of ethernet la ns
Chapter 2. fundamentals of ethernet la ns
 
Chapter 1.2 osi layer
Chapter 1.2 osi layerChapter 1.2 osi layer
Chapter 1.2 osi layer
 
Chapter 1. introduction to tcpip networking
Chapter 1. introduction to tcpip networkingChapter 1. introduction to tcpip networking
Chapter 1. introduction to tcpip networking
 

Recently uploaded

Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

2. basics of python

  • 1. Here in this class we will deal with Network Automation with the help of Python FOR CLASSES CALL +91-9790901210 www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 Python 3 for Network Engineers
  • 2. Basics of Python • Understand a point, Coding is not all about how much you know, its all about what are the stuffs you can based on how much you know. • Lets get started quickly. We will have 2 sessions in this course. • 1st session will introduce the possible commands and explanation • 2nd session we will jump into Python for Network Engineers www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
  • 3. What Python can do • We can create games, software’s etc • However we will focus on Python feature that’s helping the network engineer to make our job easy. www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
  • 5. Overview • There are 8 comparison operators in python. • All have same priority. • They can chained arbitrarily like x<y<=z is equivalent to x<y and y<=z www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 Operation Meaning < Strictly less than <= Less than or equals to > Strictly greater than >= Greater than or equals to == Equals != Not equals Is Object identity Is not Negated object identity
  • 6. Comparison operator You can below commands to check www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 x=7 # here you are assigning a value to the variable x x==5 #comparig if x is equal to 5 x==6 x==8 x<7 x>8 x<9 x=7 x 7 x<10 True x<5 False x==9 False x==10 False x>=3 True x<8 True x!=7 False Command Output x>3 and x>4 True x>1 or x>100 True Using “and” “or”
  • 7. Boolean operators AND , OR Below table you can use www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 >>>True and True True >>>True and False False >>>True or False True >>>False or False False >>>Boo1=True >>>Boo2=False >>>Boo1 and Boo2 True >>>Boo1=True >>>Boo1 not False >>>’Network’==‘network’ False >>>’Network’==‘Network’ True
  • 8. Lists with Boolean We can check if the List is empty or not. www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 >>>List2=['Vishnu','Vardhan'] >>>List2 ['Vishnu', 'Vardhan'] >>>if List2: ... print("The list is not empty") ... else: ... print("The list is empty") ... The list is not empty
  • 9. Creating a List using Split You can chop a string to create a list. www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 >>>Name="Vishnu/Vardhan/Maddy/Rock" >>>Name 'Vishnu/Vardhan/Maddy/Rock' >>>Name.split("/") ['Vishnu', 'Vardhan', 'Maddy', 'Rock'] >>>Name="vishnu Vardhan" >>>Name.split(" ") ['vishnu', 'Vardhan'] >>>List1=Name.split(" ") >>>List1 ['vishnu', 'Vardhan'] >>>List1[1] 'Vardhan' >>>List1[0] 'vishnu' >>>Name[0] 'v'
  • 10. Lists Vs Tuples Tuples are Immutable meaning once set the values cannot be changed. They collet some heterogeneous values. Lists are Mutable meaning these values can be changed They collect only homogeneous values. www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
  • 11. Lists in Lists We can use Lists inside a list. www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 >>>List1=['R1','R2','R3'] >>>List2=['S1','S2','S3'] >>>List1 ['R1', 'R2', 'R3'] >>>List2 ['S1', 'S2', 'S3'] >>>List3=[List1,List2] >>>List3 [['R1', 'R2', 'R3'], ['S1', 'S2', 'S3']] >>>List3[0][1] #Using this you can check 1st list second value 'R2' >>>List3[1][2] 'S3
  • 12. Extending a lists We can extend a list using .extend command like below www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 >>>List1 ['R1', 'R2', 'R3'] >>>List1.append("R4") >>>List1 ['R1', 'R2', 'R3', 'R4'] >>>List2 ['S1', 'S2', 'S3'] >>>List1.extend(List2) List1 ['R10', 'R2', 'R3', 'R4', 'S1', 'S2', 'S3'] >>>Router_list1=['R1', 'R2', 'R3', 'R4'] >>>Router_list2=['R5','R6','R7','R8'] >>>Router_list2 += Router_list2 >>>Router_list1 ['R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8']
  • 13. Other stuffs we can do with Lists Below link can help you to find a reference. https://docs.python.org/2/tutorial/datastructures.html www.networkrhinos.com | Vishnu (Founder) | +91-9790901210 >>>Router_list1=['R1', 'R2', 'R3', 'R4'] >>>Router_list1.insert(0,"R0") ['R0','R1', 'R2', 'R3', 'R4']
  • 14. www.networkrhinos.com | Vishnu (Founder) | +91-9790901210