Hello fellow Finxters! I am back with another installment of top 10 cheat sheets. This time, we will be compiling a list of Python Object Oriented Programming (OOP) cheat sheets to make it easier to write programs to keep on hand! Let us dig right in without wasting any more time!
💎 Cheat sheet to prep for technical interviews. Topics java computer-science algorithms guide data-structures cheatsheet interviews software-engineering coding-interviews interview-preparation technical-interviews. Python Cheat Sheet just the basics Created By: arianne Colton and Sean Chen. Data structures Note:. 'start' index is included, but 'stop' index is NOT. start/stop can be omitted in which they default to the start/end. § Application of 'step': Take every other element list1::2 Reverse a string str1::-1 DICT (HASH MAP). Python Cheat Sheet: Python is a multi-paradigm general-purpose, object-oriented programming languageIt is a cross-platform programming language.
Here’s the cheat sheet created by Finxters—downloadable as a simple, plain PDF:
This 7-page cheat sheet is one to keep handy on the desk when you are first trying to understand OOP in Python. It has full explanations and examples giving you a full scope of classes, inheritance, and naming conventions for best practices. It perfect for beginners and those who need a refresher.
Pros: Rated ‘E’ for everyone. This cheat sheet is great for everyone.
Cons: It can be a lengthy read; I would suggest highlighting the parts you really need.
Codecademy is great place to learn coding in general. This cheat sheet shows you about classes and methods used to perform certain action in your programming. By visiting this link, you will also have access to other cheat sheets for functions, control flow, and other topics. It is perfect for beginners, it has explanations with code examples to show you how the method works.
Pros: Rated ‘E’ for everyone.
Cons: None that I can see.
This cheat sheet goes over the basics of Python neatly separated into little boxes. It is great if you just need a quick reminder. This cheat sheet however has minimal explanation and no examples. I would leave this one to intermediate Pythoniers.
Pros: Easy to read and understand.
Cons: No examples to see how the method runs
Taken from Python crash course by nostrachpress.com. This cheat sheet is 27 pages and covers Python 2 and 3. Complete with explanations that take you from the basics to Django. This cheat sheet is one you will want to keep handy! I know I do, tagged and highlighted!
Pros: Covers everything you need to know about Python.
Cons: It is a lengthy read.
Tutorials Point is a great place to start if you want to learn Python! This cheat sheet is straight to the point, done in black and white. It has explanations and examples. It is great for the beginner Pythonier.
Pros: Rated ‘E’ for everyone. Contains all the information you need.
Cons: It is a lengthy read, 8 pages in length.
From ISU Computer Science, this cheat sheet has all the Python keywords, concepts and functions. It is a great quick guide, though I would say for intermediate Pythoniers who do not need a lot of explanation.
Pros: Easy to read and understand
Cons: Not for beginners.
CodeGrepper is a wonderful chrome extension made for beginner and advanced developers allowing you to spend more time developing and less time searching for answers. This cheat sheet gives you a code example explanation on the various methods in OOP for Python.
Pros: Rated ‘E’ for everyone.
Cons: None that I can see.
This quick cheat sheet gets straight to the point with code examples. It is a good one to keep pinned above the monitor.
Pros: Rated ‘E’ for everyone. Easy to understand.
Cons: None that I can see.
This cheat sheet is one to keep handy as you are developing your app! Highlight most commonly used functions and have an in depth understanding of Python OOP.
Pros: Rated ‘E’ for everyone. One to keep on hand for sure!
Cons: It is a lengthy read.
This cheat sheet will introduce Python and give code examples on the different methods and functions in Python.
Pros: Rated ‘E’ for everyone
Cons: None that I can see.
I found this cheat sheet last minute and even though it is not an actual cheat sheet for OOP syntax it is a cheat sheet of the best resources to learn OOP in Python. I have each one bookmarked in my browser so I can understand OOP better myself!
Related Articles:
Python cheat sheet enables users of Python with quicker operations and more ease of use. Python is a widely used high-level programming language created by Guido van Rossum in the late 1980s. So today I am going to tell you all the secret shortcuts and all cheat codes to make your speed 4x in python coding.
Help Home Page | help() |
Function Help | help(str.replace) |
Module Help | help(re) |
The python module is simply a '.py' file
List Module Contents | dir(module1) |
Load Module | import module1 * |
Call Function from Module | module1.func1() |
Check data type : type(variable)
str1 = r'thisf?ff'
Create datetime from String | dt1 = datetime. strptime('20091031', '%Y%m%d') |
Get 'date' object | dt1.date() |
Get 'time' object | dt1.time() |
Format datetime to String | dt1.strftime('%m/%d/%Y %H:%M') |
Change Field Value | dt2 = dt1.replace(minute = 0, second = 30) |
Get Difference | diff = dt1 - dt2 # diff is a 'datetime.timedelta' object |
All non-Get function calls i.e. list1.sort() examples below are in-place (without creating a new object) operations unless noted otherwise.
One dimensional, fixed-length, immutable sequence of Python objects of ANY type.
Create Tuple | tup1 = 4, 5, 6 or tup1 = (6,7,8) |
Create Nested Tuple | tup1 = (4,5,6), (7,8) |
Convert Sequence or Iterator to Tuple | tuple([1, 0, 2]) |
Concatenate Tuples | tup1 + tup2 |
Unpack Tuple | a, b, c = tup1 |
Swap variables | b, a = a, b |
One dimensional, variable length, mutable (i.e. contents can be modified) sequence of Python objects of ANY type.
Create List | list1 = [1, 'a', 3] or list1 = list(tup1) |
Concatenate Lists | list1 + list2 or list1.extend(list2) |
Append to End of List | list1.append('b') |
Insert to Specific Position | list1.insert(posIdx, 'b') |
Inverse of Insert | valueAtIdx = list1. pop(posIdx) |
Remove First Value from List | list1.remove('a') |
Check Membership | 3 in list1 => True |
Sort List | list1.sort() |
Sort with User Supplied Function | list1.sort(key = len) # sort by length |
WARNING: bisect module functions do not check whether the list is sorted, doing so would be computationally expensive. Thus, using them in an unsorted list will succeed without error but may lead to incorrect results.
Sequence types include 'str', 'array', 'tuple', 'list', etc.
Notation | list1[start:stop] list1[start:stop:step] (If step is used) |
NOTE:
Application of 'step' :
Create Dict | dict1 = {'key1' :'value1', 2 :[3, 2]} |
Create Dict from Sequence | dict(zip(keyList, valueList)) |
Get/Set/Insert Element | dict1['key1']* dict1['key1'] = 'newValue' |
Get with Default Value | dict1.get('key1', defaultValue) |
Check if Key Exists | 'key1' in dict1 |
Delete Element | del dict1['key1'] |
Get Key List | dict1.keys() |
Get Value List | dict1.values() |
Update Values | dict1.update(dict2) # dict1 values are replaced by dict2 |
Create Set | set([3, 6, 3]) or {3, 6, 3} |
Test Subset | set1.issubset (set2) |
Test Superset | set1.issuperset (set2) |
Test sets have same content | set1 set2 |
Union(aka 'or') | set1 | set2 |
Intersection (aka 'and') | set1 & set2 |
Difference | set1 - set2 |
Symmetric Difference (aka 'xor') | set1 ^ set2 |
Python is passed by reference, function arguments are passed by reference.
• Basic Form :
NOTE:
What is Anonymous function?
#def func1(x) : return x * 2
Application of lambda functions: 'curring' aka deriving new functions from existing ones by partial argument application.
There are 4 Useful functions for data structures
Enumerate returns a sequence (i, value) tuples where i is the index of the current item.
Application: Create a Dict mapping of the value of a sequence (assumed to be unique) to their locations in the sequence.
Sorted returns a new sorted list from any sequence
returns sorted unique characters
Zip pairs up elements of a number of lists, tuples, or other sequences to create a list of tuples
Reversed iterates over the elements of a sequence in reverse order.
1. Operators for conditions in 'if else' :
Check if two variables are the same object | var1 is var2 |
are different object | var1 is not var2 |
Check if two variables have the same value | var1 var2 |
WARNING: Use 'and', 'or', 'not' operators for compound conditions, not &&, ||, !.
2. Common usage of 'for' operator
Iterating over a collection (i.e. list or tuple) or an iterator | for element in an iterator |
If elements are sequences, can be 'unpack' | for a, b, c in iterator |
3. 'pass' - no-op statement. Used in blocks where n action is to be taken.
4. Ternary Expression - aka less verbose 'if else'
5. No switch/case statement, use if/elif instead.
There are ways to do this.
4. Class Basic Form
5. Useful interactive tool
There are 5 common string Operators
2. Format String
3. Split String
4. Get Substring
5. String Padding with Zeros
1. Basic Form
2. Raise Exception Manually
Syntactic sugar that makes code easier to read and write
Basic form :
A shortcut for :
The filter condition can be omitted, leaving only the expression.
2. Dict Comprehension
3. Set Comprehension
Basic form: same as List Comprehension except with curly braces instead of []
4. Nested list Comprehensions
Thank you for reading this post. If you were like this post then please tell us which shortcut you like most and anything I forget to add in this post then please tell us in the comments thank you.