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 Variables
local scope | contains inside of a function
example: x, y |
global scope | contains all python code
examle: z |
printing variables |
Output: |
variable class |
Output: |
Python Lists
number list | |
string list | |
list length |
Output: |
adding item |
Output: |
removing item |
Output: |
sorting list |
Output: |
reverse sort |
Output: |
pop item |
Output: |
reverse list |
Output: |
comprehension |
Output: |
finding Index |
Output: |
Python Tuples
number tuple | |
string tuple | |
finding tuple member |
Output: |
printing tuple isle |
Output: |
Counting members |
Output: |
Tuple length |
Output: |
Couting an item |
Output: |
for loop with tuple |
Output: |
Python Sets
string set | |
number set | |
mixed set | |
union set |
Output: |
adding item |
Output: |
removing item |
Output: |
clear set |
Output: |
finding difference |
Output: |
If Statements
if statement | |
If, else statement | |
if, elif,else statement | |
finding even/odd |
Output: |
continue statement |
Output: |
nested if |
Output: |
if, elif,else |
Output: |
if, elif,else with list |
Output: |
Python While Loop
python while loop | |
printing numbers |
Output: |
break statement |
Output: |
continue statement |
Output: |
Python File Operations
open function modes |
|
content of filexyz.txt | Weak people revenge. Strong people forgive. Intelligent people ignore. |
file read and print |
Output: |
file write | |
file append |
Output: |
file create | |
file remove |
Pyhton Modules
Python modules | https://docs.python.org/3/py-modindex.html |
extention | .py |
using a module | |
using part of a module | |
creating a module |
record this file as “ourmodule.py“. Output: |
module alias | |
listing module functions |
Output: |
Python PIP Install
checking PIP version | |
installing PIP | |
listing installed packages | |
unistall a package (xyz) | |
using a package (xyz) |
Python Math
math operators | + (addition)
– (subtraction) * (multiplication) / (divide) % (difference) ** (power) |
math operations |
Output: |
finding odd number |
Output: |
min, max functions |
Output: |
pow function |
Output: |
sqrt function |
Output: |
factorial function |
Output: |
ceil/floor functions |
Output: |
pi function |
Output: |
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 |
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) |
Python Strings
python string | |
string length |
Output: |
using format |
Output: |
string split |
Output: |
string replace |
Output: |
string contains |
Output: |
string find |
Output: |
string slice |
Output: |
string slice |
Output: |
concatenation |
Output: |
capitalize |
Output: |
title |
Output: |
lower |
Output: |
upper |
Output: |
count |
Output: |
join |
Output: |
partition |
Output: |
endswith |
Output: |
Python Dictionaries
python dictionary | |
dictionary length |
Output: |
access item |
Output: |
access item (with get) |
Output: |
adding items |
Output: |
changing value |
Output: |
changing value (with update) |
Output: |
removing an item |
Output: |
removing last item |
Output: |
concatenation |
Output: |
capitalize |
Output: |
title |
Output: |
lower |
Output: |
upper |
Output: |
count |
Output: |
join |
Output: |
partition |
Output: |
endswith |
Output: |
Python For Loops
python for loop | for value in sequence
body (any action) |
for loop with lists |
Output: |
for loop with strings |
Output: |
for loop with if/else |
Output: |
break statement |
Output: |
continue statement |
Output: |
nested for loops |
Output: |
Python Functions
creating function | |
calling function |
Output: |
function with numbers |
Output: |
function with strings |
Output: |
default value |
Output: |
using asterisk (*) |
Output: |
using asterisk (*) |
Output: |
return statement |
Output: |
pass statement |
Used to get no error in empty function. |
recursive function |
Output: |
lambda function |
Output: |
lambda with filter func. |
Output: |
lambda with map func. |
Output: |
try/except function |
Output: |
try/except function |
Output: |
try/except/finally |
Output: |
try/except/else |
Output: |
raise function |
Output: |
Comparison Characters
== | Equal |
!= | Not Equal |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
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) |
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.
Leave a Reply