Python Cheat Sheet – Python for Beginner

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

ActionPython Cheatsheet Code
Converts to uppercasestring.upper()
Converts to lowercasestring.lower()
Counts how many times x appearsstring.count(x)
position of the x first occurencestring.find(x)
replaces x for ystring.replace(x,y)
returns a list of values delimited by xstring.strip(x)
returns a string with L values joined by stringstring.join(L)
returns a string that includes formatted xstring.format(x)

Python List Methods

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

Python Built-in Functions

ActionPython Code
Prints x objects separated by yprint(x, sep=’y’)
prints s and waits for an input that will be returnedinput(s)
returns the length of x (s, L or D)len(x)
returns the minimum value in Lmin(L)
returns the maximum value in Lmax(L)
returns the sum of the values in Lsum(L)
returns the absolute value of nabs(n)
returns the n1 number rounded to n digitsround(n1, n)

Python Dictionary Methods

ActionPython Cheatsheet Code
returns a list of keysdict.keys()
returns a list of valuesdict.values()
returns a list of pairsdict.items()
returns the value associtated to the keys kdict.get(k)
Removes the item associated to the keys and returns its valuedict.pop()
adds keys-values to dictionarydict.update(D)
removes all keys values from the dictionarydict.clear()
returns a copy of the dictionarydict.copy()

Main data types

ActionPython Code
booleanTrue/False
integer10
float10.01
string“123abc”
list[value1, value2, …]
dictionary{key1:value1, key2:value2, …}

List Operations

ActionPython Code
defines an empty listlist=[]
stores x with index ilist[i]=x
retrieves the item with index ilist[i]
retrieves last itemlist[-1]
retrieves items in the range i to jlist[i:j]
removes the item with index idel list[i]

Numeric Operations

ActionPython Cheatsheet Code
Addition+
Subtraction
Multiplication*
division/
exponent**
Modules%
Floor division//

Comparison Operations

ActionCode
Equal==
different!=
higher>
lower<
higher or equal>=
lower or equal<=

Dictionary & Boolean Operations

ActionCode
defines an empty dictionarydict={}
stores x associated to keys kdict[k] = x
retrieves the item with keys kdict[k]
removes the item with keys kdel dict[k]
logical ANDand
logical ORor
logical NOTnot

Special Characters

ActionCode
Coment#
new line\n
scape char\

String Operations

ActionCode
retrieves character at position istring[i]
retieves last characterstring[-1]
retrieves characters in range i to jstring[i:j]

Learn more

Windows Run Commands you Should know

Handbrake Alternative absolutely FREE

Top 10 features of Handbrake software

101 Tableau Shortcuts for Visualization you should know

Download Handbrake for Windows and Mac – Installation Guide

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. Connect with us and Take your Office Productivity to Next Level.

Crazy Shortcut
Crazy Shortcut helps you to be more productive by using Shortcuts and optimising your skills. We are helping our viewers to use your skills to the fullest.