Disha NEET Physics Guide for classes 11 and 12.pdf
Network Automation with Python
1. Here in this class we will deal with Network
Automation with the help of Python
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
Python 3 for Network Engineers
2. Software to RUN network Automation
• Pycharm – By. Jetbrains – Download Community version
• GNS3VM
• GNS3
• Virtual Box
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
3. 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
4. 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
6. Printing “ Hello world “
• Print is a command which is used to print any strings or characters or values etc.
Command :
>>>print (“Hello World”)
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
8. Variables and Multiple assignments
• Variables :
• Variables are basically memory locations where we can store values.
• Commands :
>>>age = 20
>>>sentence = “my name is vishnu”
>>>bob = 20
>>>john = 24
>>>steve = 30
>>> bob,john,steve = 20,24,30
>>>name,age = “vishnu”,28 ------ Am storing string and integer at the same place.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
9. Variables and Multiple assignments Practice
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
11. Arithmetic Operations
• Last slides we saw what are variables and stuffs. Lets do some maths with Python.
• We have Addition, Subtraction, Multiplication, Division
Commands : For adding and subtracting numbers
>>>a=10
>>>b=20
>>>a+b
Commands : For adding two or more strings
>>>firstname = “Vishnu”
>>>lastname = “Vardhan”
>>>details = “age is 28”
>>>firstname + lastname + details
or
>>>firstname + “ “ + lastname+ “ “ +details
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
12. Arithmetic Operations
• Oh good that now you got how to add two different names by using “+”. But if you try to use “-” then it
will not work for strings.
• You can use “*” (Multiplication) with Strings
• String supported operations are = + and *
• String non supported operations are = % and -
15. String Functions - Slicing
• Functions are the additional power commands given to Strings we have lot, let us start with Slicing.
Command:
>>>sentence=“Welcome to network rhinos classes”
>>>sentence[0]
‘W’
>>>sentence[4]
‘o’
?? What if you want full length character.
>>>sentence[0:6] ------ Make note Blank spaces also count
‘Welcome’
>>>sentence[:6]
‘Welcome’
>>>sentence[0:-2]
‘Welcome to network rhinos class’
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
16. String Lab and intro to docs.python.org
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
17. Errors while slicing
• What if you try to slice a value or character with a wrong index value.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
18. Placeholders in String
• As of not we have covered Integers, Arithmetic's, Strings and some functions.
• Lets get our self familial with Placeholders
• ?? What is Placeholders :
• Taking a place of something.
>>>name = “Bob”
>>>details = “is 15 years old”
‘Bob is 15 years old’
I can simply use something called placeholder to say hey instead of placeholder use this value ( %s )
>>>detail=“%s is 15 years old”
>>>detail%name
‘Bob is 15 years old’
** Here you can see the %s is being replaced by name in the output.
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
21. Introductions Lists
• Pythons first Data structures.
• What is Lists :
It can be set of items which are ordered with index and each least value has items. You can think of Shopping lists.
Like Item 1= banana , Item 2=apple etc etc.,
Lists are always enclosed in square braces and separated by commas
Command :
>>>shoplist=[“Apples”,”Oranges”,”Bananas”,”Choclates”]
>>>shoplist
[‘Apples’,’Oranges’,’Bananas’,’Choclates’]
In list index value works for a list number unlike in strings it worked for a character.
>>>shoplist[0]
‘Apples’
>>>shoplist[1]
‘Oranges’
>>>shoplist[0:2] # To see first 2 items
Apples, Oranges
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
22. Adding a new value to the Lists
• What if you missed something on the list and you want to add it later.
Command :
>>>shoplist.append[“Blueberrys”]
>>>shoplist
[‘Apples’,’Oranges’,’Bananas’,’Choclates’,Blueberrys]
• What if you want to change something in the list.
Command :
>>>shoplist[0] = “Coconets”
>>>shoplist
[‘Coconets’,’Oranges’,’Bananas’,’Choclates’,Blueberrys]
• To remove from a lists.
Command :
>>>del shoplist[1]
[‘Coconets’,’Bananas’,’Choclates’,Blueberrys]
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
23. • You can also add two lists by just using a “+”
Counting number of items
Command :
>>>len(shoplist)
4
• Finding maximum number on a lists :
Command:
>>>list1=[1,2,3,4,5,6,7]
>>>max(list1)
7
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210
25. Dictionaries
• Dictionaries are the are the list but with a meaning to each item.
• For example I want to create student and age dictionary.
• We will be using “:” between them key and meaning.
Command :
>>>students= {“Bob”:12 , “Steve”:15,”Mark”:20}
>>>students[“Bob”]
12
• What if we want to update the students age. Simply use the above command with = <age>
Command :
>>>students[“Bob”]=25
>>>students[“Bob”]
25
Deleting : >>>del students[“Bob”]
Counting : >>>len(students)
www.networkrhinos.com | Vishnu (Founder) | +91-9790901210www.networkrhinos.com | Vishnu (Founder) | +91-9790901210