A Python cheat sheet can be helpful when working on a specific topic or project. Only a minimum amount of information can be set on a single sheet so the Cheatsheet mostly consists of the most useful rules.

Most used Python Cheat Sheet

To make working and learning of Python easy, I’ve created a Python 3 cheat sheet to help remember the syntax. This Python Cheat sheet aims to remind you of the rules and important concepts. You can download the Python Cheat sheet PDF here.

Also, this Python Cheatsheet mainly focuses on common snippets in Python Code. It focuses on features, data structure and algorithms like Main data types, list operations, numeric operators, comparison operators, string methods, string operations, Dictionary operations, etc.

  • Python String Method: Shows how to perform a common string method or actions in Python.
  • Numeric Operators: Testing of numeric values is similar to testing string values in Python.
  • Comparison Operators: Comparison operators are used when testing conditional formatting in Python.
  • Boolean Operator: Boolean Operator will either return True or False.

Python String Methods

Action Code
Converts to uppercase string.upper()
Converts to lowercase string.lower()
Counts how many times x appears string.count(x)
position of the x first occurence string.find(x)
replaces x for y string.replace(x,y)
returns a list of values delimited by x string.strip(x)
returns a string with L values joined by string string.join(L)
returns a string that includes formatted x string.format(x)

Python List Methods

Action Code
Adds x to the end of the list list.append(x)
appends L to the end of the list list.extend(L)
inserts x at i position list.insert(i,x)
removes the first list item whose value is x list.remove(x)
removes the item at position i and returns its value list.pop(i)
removes all items from the list list.clear()
returns a list of values delimited by x list.index(x)
returns a string with list values joined by S list.count(x)

Python Built-in Functions

Action Code
Prints x objects separated by y print(x, sep=’y’)
prints s and waits for an input that will be returned input(s)
returns the length of x (s, L or D) len(x)
returns the minimum value in L min(L)
returns the maximum value in L max(L)
returns the sum of the values in L sum(L)
returns the absolute value of n abs(n)
returns the n1 number rounded to n digits round(n1, n)

Python Dictionary Methods

Action Code
returns a list of keys dict.keys()
returns a list of values dict.values()
returns a list of pairs dict.items()
returns the value associtated to the keys k dict.get(k)
Removes the item associated to the keys and returns its value dict.pop()
adds keys-values to dictionary dict.update(D)
removes all keys values from the dictionary dict.clear()
returns a copy of the dictionary dict.copy()

Main data types

Action Code
boolean True/False
integer 10
float 10.01
string “123abc”
list [value1, value2, …]
dictionary {key1:value1, key2:value2, …}

List Operations

Action Code
defines an empty list list=[]
stores x with index i list[i]=x
retrieves the item with index i list[i]
retrieves last item list[-1]
retrieves items in the range i to j list[i:j]
removes the item with index i del list[i]

Numeric Operations

Action Code
Addition +
Subtraction –
Multiplication *
division /
exponent **
Modules %
Floor division //

Comparison Operations

Action Code
Equal ==
different !=
higher >
lower <
higher or equal >=
lower or equal <=

Dictionary & Boolean Operations

Action Code
defines an empty dictionary dict={}
stores x associated to keys k dict[k] = x
retrieves the item with keys k dict[k]
removes the item with keys k del dict[k]
logical AND and
logical OR or
logical NOT not

Special Characters

Action Code
Coment #
new line \n
scape char \

String Operations

Action Code
retrieves character at position i string[i]
retieves last character string[-1]
retrieves characters in range i to j string[i:j]

Before you start using the Python Cheat sheet make sure you have properly installed Python. If you wish to know how to install Python Click here. This python Cheatsheet will enhance the python coding experience.

Hope you have liked our blog on Python Cheat Sheet. Suggestions are always welcomed for the blog you looking forward to hearing from us. Like our My e-Learning Hub Facebook Page and Subscribe to our My e-Learning Hub YouTube Channel. Connect with us and Take your Office Productivity to Next Level.

Leave a comment

Main Office:

Andheri West, Mumbai
India

Contact Us:

hello@myelearninghub.com

MyeLearningHUB © 2019. All rights reserved.