Python Cheat Sheet

Python Basics Cheat Sheet

Python is one of the most popular programming languages in networking World. Almost all network engineers learn and use this programming language in their daily works. Because of the fact that there are many details in Python as in all programming languages, sometimes we can forget a basic command or a general concept, usage. Python Cheat Sheet has created to overcome this case and aims to remind you the missing points of this awesome network programming language. Basic Python Codes Cheat Sheet is like other sheets like CLI Command Cheat Sheet, Linux Commands Cheat Sheet etc.

python-cheat-sheet-ipcisco.com

Python Lists

number list numbers = [1,10,8,3,15]
string list cars = [“Porche”, “Aston Martin”, “Ferrari”]
list length cars = [“Porche”, “Aston Martin”, “Ferrari”]

length = len(cars)

print(length)

Output: 3

adding item elves = [“Legolas”, “Elrond”]

elves.append(“Arwen”)

print(elves)

Output: [“Legolas”, “Elrond”, “Arwen”]

removing item list = [6, 15, 24, 36, 55]

list.remove(24)

print(list)

Output: [6, 15, 36, 55]

sorting list list = [85, 9, 3, 15, 75, 23]

list.sort()

print(list)

Output: [3,9,15,23,75,85]

reverse sort list = [85, 9, 3, 15, 75, 23]

list.sort(reverse=True)

print(list)

Output: [85,75,23,15,9,3]

pop item numbers = [14,26,45,76,95]

numbers.pop(3)

print(numbers)

Output: [14, 26, 45, 95]

reverse list numbers = [1,2,3,4,5]

numbers.reverse()

print(numbers)

Output: [5, 4, 3, 2, 1]

comprehension

(finding sth in the list)

list1 = [“152”, “4”, “98”, “169”, “16”]

list2 = [x for x in list1 if “9” in x]

print(list2)

Output: [’98’, ‘169’]

finding Index numbers = [5,9,45,7,126,4]

x = numbers.index(45)

print(x)

Output: 2

Escape Characters

\b Backspace
\r  Carriage Return
\f  Form Feed
\xhh Hex value
\n New Line
\ooo Octal value
\’  Single Quote
\t Tab
\\ Backslash

Arithmetic Operators

+ Addition
–  Subtraction
* Multiplication
/ Division
% Modulus
** Exponentiation
//  Floor division

Assignment Operators

= Asign (x = 1)
+=  Add AND  (x += 2) (x=x+2)
-= Subtract AND (x -= 2) (x=x-2)
*= Multiply AND (x *= 2) (x=x*2)
/= Divide AND (x /= 2) (x=x/2)
%= Modulus AND (x %= 3) (x = x % 3)
//= Divide Floor AND (x //= 3) (x = x // 3)
**= Exponent AND (x **= 3) (x = x ** 3)
&= Bitwise AND (x &= 4) (x = x & 4)
|= Bitwise OR (x |= 4) (x = x | 4)
^= Bitwise xOR (x ^= 4) (x = x ^ 4)
>>= Bitwise Right Shift (x >>= 5) (x = x >> 5)
<<=  Bitwise Left Shift (x <<= 5) (x = x << 5)

Python Strings

python string “Hello”
string length message = “hello,how are you?”

print(len(message))

Output: 18

using format number1 = 2

number2 = 1

message = “I have {} cats and {} dog.”

print(message.format(number1, number2))

Output: I have 2 cats and 1 dog.

string  split message = ‘life is good’

print(message.split())

Output: [‘life’, ‘is’, ‘good’]

string replace msg = “I have two dogs, two cats.”

newmsg = msg.replace(“three”, “two”)

print(newmsg)

Output: I have three dogs, three cats.

string contains msg = “Istanbul is in Turkey.”

print(msg.find(“Turkey”))

Output: 15

string find msg = “I like cats.”

print(msg.find(“cats”))

Output: 7

string slice x = “Hello World!”

print(x[2])

Output: l

string slice x = “Hello World!”

print(x[3:5])

Output: lo

concatenation print (“Hello” + “Python” + “World”)

Output: HelloPythonWorld

capitalize msg = “welcome to python course!”

x = msg.capitalize()

print (x)

Output: Welcome to python course!

title msg = “welcome to python course!”

x = msg.title()

print (x)

Output: Welcome To Python Course!

lower msg = “weLcoMe to PytHon CouRse!”

x = msg.lower()

print (x)

Output: welcome to python course!

upper msg = “weLcoMe to PytHon CouRse!”

x = msg.upper()

print (x)

Output: WELCOME TO PYTHON COURSE!

count msg = “I like cats. Because cats are cute.”

x = msg.count(“cats”)

print(x)

Output: 2

join characters = [“Aragorn”, “Arwen”, “Legolas”]

print (“-“.join(characters))

Output: AragornArwenLegolas

partition msg = “welcome to python course”

x = msg.partition(“to”)

print(x)

Output: (‘welcome ‘, ‘to’, ‘ python course’)

endswith msg = “weLcoMe to PytHon CouRse!”

x = msg.endswith(“!”)

Output: True

Comparison Characters

== Equal
!= Not Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Bitwise Operators

& AND (Sets each bit to 1 if both bits are 1)
| OR (Sets each bit to 1 if one of two bits is 1)
^ XOR ( Sets each bit to 1 if only one of two bits is 1)
~ NOT (Inverts all the bits)
<< Zero fill left shift (Shift left by pushing zeros in from the right and let the leftmost bits fall off)
>> Signed right shift (Shift right by pushing copies of the left most bit in from the left, and let the rightmost bits fall off)

Other Operators

and returns True, if both statements are true.
or returns True, if one of the statements is true.
not reverse the result, returns False if the result is true.
is checks that if both objects are the same object. If yes, it returns True.
is not checks that if both objects are different objects. If yes, it returns True.
in returns True, if it finds the value as a member in the sequence.
not in returns True, if it do not find the value as a members in the sequence.

You can use Python in another area than networking certainly. Whichever you use, the concepts and usage of the programming language are similar. There are only small differences and focus change in classical programming and network programming and automation.  This Python Cheat Sheet will help you not only on your network automation or network programming activities, but also it will help you in all your programming works even in another area than computer networking. So, this page will be a reference page both programmers or network engineers. Because both of these jobs use Python and the concepts sof this programming language is similar.

 

There are many Python tutorial on internet and you can download Python free on internet. But it is difficult to have such a Ptyhon Cheat Sheet, that covers almost all important parts of Ptyhon programming language. It can be a quick reference for you or a document that you remind key parts. Whichever it is, this page will help you a lot and will decrease your exploration period for any code part.

 

You can find Python list, range, class, dictionary or any other concepts on this page. We will cover all basic Python terms here. So, by having Pyhton Cheat Sheet, you will have a strong partner with you during your Ptyhon adventure.

 


 

Python Cheat Sheet For Beginners

Python Cheat Sheet has prepared for both beginner users and Python experts. So, you can use this sheet as Pyhton Cheat Sheet For Beginners and For Experts. The programming language is similar and in this page, we will cover all these basic concepts.

 

If you use this sheet as Python beginner cheat sheet, you can use it during your programming activities. You can download this cheat sheet and you can use it on your computer during code writing. You can also use this Ptyhon Cheat Sheet online.

 

If you use this sheet as expert reference, you can use it whenever you need to remember a Python code or usage. This page will help you in your critical coding activities.

 

Every tech guy was a beginner before. So, if you are a beginner now, you will be an expert too in the future. During this period, during your Python journey, this document will be always with you and you will benefit a lot from this page.

 


 

Python Cheat Sheet Pdf

This reference document can be used both online on our website or you can download Python Cheat Sheet pdf and use offline on your computer. Whichever you use, this excellent Ptyhon Cheat Sheet pdf will help you a lot.

 

When you download Python Cheat Sheet Pdf, you can use it to remember any Python code. This can be any Python code. Maybe you do not remember, Python list, dictionary, ranges etc. Maybe you remember the codes but you forgot the usage. Whichever it is, you can find on this page and with this page, you will not struggle on internet to find any Python code.

 

 


 

 

Python Interview Cheat Sheet

Python Cheat Sheet can be used also for your Python Job interview. Before your technical interview, you can check this sheet and you can use it as Python Interview Sheet. You can find all the basic terms of Python programming languages in this cheat sheet. So, the questions in you technical Python interview will be mostly on this Python Interview Cheat Sheet.

 

In your Python interview, maybe they will ask how to use Python tubles? Maybe they want to learn, how to get the last term in a Python list. Or maybe their question will be, how to get different types of inputs from the user.

 

Beside basic questions, in the Python Interview, they can ask complex questions about a programming code part. They can ask any specific parts of a Python program in the interview. Python Interview Cheat Sheet can remind you basic terms for this complex questions.

 


If You Like, Kindly Share

If you find this page useful for your Python works and if you like it, kindly share this page with your friends, with your colleagues, with your social media followers etc. Whoever you share this knowledge, this will help us to develop better cheat sheets.

 

You can share this page in your social media accounts like facebook, linkedin, twitter etc., in related network and programming forums, in your blogs, in any of your accounts. If you share this page, this page will help another network, programming fan and it eases his/her work. So, if you would like to help others, kindly share this page.

 

Do not forget, Knowledge Increases by Sharing.

python-cheat-sheet-ipcisco

Leave a Reply

Your email address will not be published.