0% found this document useful (0 votes)
17 views

Best - and - Good - Python Cheat Sheet

Uploaded by

Ashutosh Panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Best - and - Good - Python Cheat Sheet

Uploaded by

Ashutosh Panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Cheat Sheet

Core Concepts
Data Types:
● Numeric: int, float, complex
● Boolean: True, False
● String: Sequence of characters
● List: Ordered collection of items
● Tuple: Immutable ordered collection of items
● Set: Unordered collection of unique items
● Dictionary: Unordered collection of key-value pairs
Operators:
● Arithmetic: +, -, *, /, //, %, **
● Comparison: ==, !=, <, >, <=, >=
● Logical: and, or, not
● Bitwise: &, |, ^, ~, <<, >>
Control Flow:
● if/else: Conditional execution
● for: Looping over a sequence
● while: Looping while a condition is true
● break: Exits a loop
● continue: Skips the current iteration of a loop
Functions:
def function_name(parameters):
# code
return value

Data Structures
Lists:
● Creation: list_name = [item1, item2, ...]
● Accessing: list_name[index]
● Slicing: list_name[start:end:step]
● Methods: append, insert, remove, pop, clear, sort, reverse
Tuples:
● Creation: tuple_name = (item1, item2, ...)
● Accessing: tuple_name[index]
● Immutable: Cannot be modified after creation
Sets:
● Creation: set_name = {item1, item2, ...}
● Unordered and Unique: Elements are not stored in a specific order and duplicates are
removed.
● Methods: add, remove, union, intersection, difference
Dictionaries:
● Creation: dict_name = {key1: value1, key2: value2, ...}
● Accessing: dict_name[key]
● Methods: keys, values, items, get, update, pop
Modules and Packages
● Importing Modules: import module_name
● Creating Modules: A Python file containing functions and variables.
● Packages: A collection of modules organized in a hierarchical structure.
Input/Output
● Reading Input: input()
● Printing Output: print()
● File I/O: open(), read(), write(), close()
Object-Oriented Programming (OOP)
● Classes and Objects:
○ Class: A blueprint for creating objects.
○ Object: An instance of a class.
● Inheritance:
○ Single Inheritance: A class inherits from one parent class.
○ Multiple Inheritance: A class inherits from multiple parent classes (not directly
supported in Python, but achieved using mixins).
● Polymorphism:
○ Method Overloading: Multiple methods with the same name but different
parameters.
○ Method Overriding: A subclass provides a specific implementation of a method
inherited from a superclass.
● Encapsulation:
○ Hiding the implementation details of a class and exposing only the necessary
interface.
Functional Programming
● Lambda Functions: Anonymous functions defined using the lambda keyword.
● Higher-Order Functions: Functions that take other functions as arguments or return
functions as results.
● Map, Filter, Reduce: Functions for transforming, filtering, and reducing sequences.
Remember to practice regularly and experiment with different Python concepts to solidify
your understanding.

You might also like