python_intro
Jupyter notebooks in Russian. Introduction to Python, basic algorithms and data structures
- 610
- Jupyter Notebook
- 4 y ago
Python, created by Guido van Rossum and first released in 1991, is widely used in web development, data science, AI, and more. Refer to this Python cheatsheet by Aarya for a quick guide.
Repo Aaryacode19/Python-Cheatsheet, read from GitHub 16 h ago. Aaryacode19 has not joined Take My Repo.
Aaryacode19/Python-Cheatsheet is a public repo on GitHub by Aaryacode19. Python, created by Guido van Rossum and first released in 1991, is widely used in web development, data science, AI, and more. Refer to this Python cheatsheet by Aarya for a quick guide. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It has 4 stars and last changed on 2024-12-17. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-19.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
The print function is used to display or print output as follows:
print("Content that you wanna print on screen")
We can display the content present in an object using the print function as follows:
var1 = "Aarya" print("Hi my name is: ", var1) print(f"Hi my name is {var1}") #using f string method
The input function is used to take input as a string or character from the user as follows:
var1 = input("Enter your name: ") print("My name is: ", var1)
To take input in the form of other data types we need to typecast them as follows:
To take input as an integer:
var1 = int(input("Enter the integer value: ")) print(var1)
To take input as a float:
var1 = float(input("Enter the float value: ")) print(var1) #similar to int and float we also have char, str etc
int: Integer numbers.
x = 5
float: Floating-point numbers (decimals).
y = 5.5
complex: Complex numbers.
z = 1 + 2j
str: String of characters.
name = "Alice"
list: Ordered, mutable collection.
fruits = ["apple", "banana", "cherry"]
tuple: Ordered, immutable collection.
point = (10, 20)
person = {"name": "Alice", "age": 25}
set: Unordered collection of unique elements.
unique_numbers = {1, 2, 3}
frozenset: Immutable version of set.
frozen_numbers = frozenset([1, 2, 3])
is_active = True
unknown = None
The range function returns a sequence of numbers, e.g., numbers starting from 0 to n-1 for range(0, n).
range(int_start_value, int_stop_value, int_step_value)
Here the start value and step value are by default 1 if not mentioned by the programmer, but int_stop_value is a compulsory parameter in the range function.
also note that int_start_value is inclusive whereas int_stop_value is exclusive
Example - Display all even numbers between 1 to 100:
for i in range(0, 101, 2): print(i)
Comments are used to make the code more understandable for programmers, and they are not executed by the compiler or interpreter.
Single line comment
# This is a single line commentMulti-line comment
'''This is a multi-line comment'''
An escape sequence is a sequence of characters; it doesn't represent itself (but is translated into another character) when used inside a string literal or character. Some of the escape sequence characters are as follows:
Newline Character: using newline character we can jump to next line, i.e. the code \n will execute in new line
print("\n")
Backslash: It adds a backslash
print("\\")
Single Quote: It adds a single quotation mark
print("\'")
Tab: It gives a tab space
print("\t")
Backspace: It adds a backspace
print("\b")
Octal value: It represents the value of an octal number
print("\ooo")
Hex value: It represents the value of a hex number
print("\xhh")
Carriage Return
Carriage return or \r will just work as you have shifted your cursor to the beginning of the string or line.
print("\r")
Python string is a sequence of characters, and each character can be individually accessed using its index. You can create Strings by enclosing text in both forms of quotes - single quotes or double quotes.
variable_name = "String Data"
Example:
str = "Aarya" print("String is ", str)
The position of every character placed in the string starts from 0th position and step by step it ends at length-1 position.

Slicing is a technique in Python used to extract a portion of a sequence (like a string, list, or tuple) by specifying a start index, an end index (exclusive), and an optional step size.
sequence[start:end:step]
text = "Hello, World!" # Extract substring from index 0 to 5 (exclusive). substring1 = text[0:5] print(substring1) # Output: "Hello" # Omit start index (starts from beginning). substring2 = text[:5] print(substring2) # Output: "Hello" # Extract substring from index 7 to end of string. substring3 = text[7:] print(substring3) # Output: "World!" # Negative index to count from end of string. substring4 = text[-6:] print(substring4) # Output: "World!" # Extract every other character. substring5 = text[::2] print(substring5) # Output: "Hlo ol!" # Reverse the string. substring6 = text[::-1] print(substring6) # Output: "!dlroW ,olleH"
True if all the characters in the string are alphanumeric, else False.string_variable.isalnum()
True if all the characters in the string are alphabets.string_variable.isalpha()
True if all the characters in the string are decimals.string_variable.isdecimal()
True if all the characters in the string are digits.string_variable.isdigit()
True if all characters in the string are lower case.string_variable.islower()
True if all characters in the string are whitespaces.string_variable.isspace()
True if all characters in the string are upper case.string_variable.isupper()
string_variable.lower()
string_variable.upper()
string_variable.strip()
A List in Python represents a list of comma-separated values of any data type between square brackets.
var_name = [element1, element2, ...]
These elements can be of different data types.
The position of every element placed in the list starts from 0th position and step by step it ends at length-1 position.
List is ordered, indexed, mutable and the most flexible and dynamic collection of elements in Python.
-Empty list: This method allows you to create an empty list.
my_list = []
list.index(element)
list.append(element)
list.extend(iterable)
list.insert(position, element)
list.pop(position)
list.remove(element)
list.clear()
list.count(value)
list.reverse()
list.sort(reverse=True|False)
Tuples are represented as comma-separated values of any data type within parentheses.
variable_name = (element1, element2, ...)
These elements can be of different data types.
The position of every element placed in the tuple starts from 0th position and step by step it ends at length-1 position.
Tuples are ordered, indexed, immutable, and the most secured collection of elements.
Tuples in Python are immutable, meaning their contents cannot be changed after creation. While methods that modify data (like append(), insert(), remove(), pop(), sort(), reverse()) are exclusive to lists, you can safely use other methods with tuples:
Querying Methods:
count(value): Returns the number of occurrences of value.index(value): Returns the index of the first occurrence of value.Utility Methods:
len(): Returns the number of items in the tuple.min(): Returns the smallest item in the tuple.max(): Returns the largest item in the tuple.Iteration and Membership Checking:
for loops to iterate over tuple elements.in and not in.my_tuple = (1, 2, 3, 2, 4) # Querying methods count_twos = my_tuple.count(2) # Output: 2 index_two = my_tuple.index(2) # Output: 1 # Utility methods tuple_length = len(my_tuple) # Output: 5 min_value = min(my_tuple) # Output: 1 max_value = max(my_tuple) # Output: 4 # Iteration and membership checking for item in my_tuple: print(item) if 3 in my_tuple: print("3 is present in the tuple") else: print("3 is not present in the tuple")
For more details, refer to the PDF.
A set is a collection of multiple values which is both unordered and unindexed. It is written in curly brackets.
Way 1:
var_name = {element1, element2, ...}
Way 2:
var_name = set([element1, element2, ...])
Set is unordered, immutable, and non-indexed type of collection. Duplicate elements are not allowed in sets.
set.add(element)
set.clear()
set.discard(value)
set.intersection(set1, set2 ... etc)
set.issubset(set)
set.pop()
set.remove(item)
set.union(set1, set2...)
For more details, refer to the PDF.
The dictionary is an unordered set of comma-separated key:value pairs, within {}, with the requirement that within a dictionary, no two keys can be the same.
<dictionary-name> = {<key>: value, <key>: value ...}
Dictionary is an ordered and mutable collection of elements. Dictionary allows duplicate values but not duplicate keys.
my_dict = {}
my_dict[key] = value
dictionary[keyname]
dict.clear()
dict.copy()
dict.fromkeys(keys, value)
dict.get(key, default=None)
dict.items()
dict.keys()
dict.pop(key)
dict.popitem()
dict.setdefault(key, default=None)
dict.update([other])
dict.values()
For more details, refer to the PDF.
Conditional statements help us to execute some particular block of statements if the specified condition is True.
if <condition>: <statement>
Example:
if 5 > 2: print("5 is greater than 2")
if <condition>: <statement> else: <statement>
Example:
if 5 > 2: print("5 is greater than 2") else: print("5 is not greater than 2")
if <condition>: <statement> elif <condition>: <statement> else: <statement>
Example:
x = 3 if x > 2: print("x is greater than 2") elif x == 2: print("x is equal to 2") else: print("x is less than 2")
if (conditional expression): if (conditional expression): statements else: statements else: statements
a = 15 b = 20 c = 12 if (a > b and a > c): print(a, "is greatest") elif (b > c and b > a): print(b, "is greatest") else: print(c, "is greatest")
Loops are used to repeat a block of code multiple times.
The for loop of Python is designed to process the items of any sequence, such as a list or a string, one by one.
for <variable> in <sequence>: <statement>
Example:
for i in range(5): print(i)
A while loop is a conditional loop that will repeat the instructions within itself as long as a conditional remains true.
while <condition>: <statement>
Example:
i = 0 while i < 5: print(i) i += 1
The break statement enables a program to skip over a part of the code. A break statement terminates the very loop it lies within.
for <var> in <sequence>: statement1 if <condition>: break #therefore every line of code after this break statement will not get execute. statement2 statement_after_loop
The continue statement skips the rest of the loop statements and causes the next iteration to occur.
for <var> in <sequence>: statement1 if <condition>: continue #therefore here statements after continue will get execute statement2 statement3 statement4
A function is a block of code that performs a specific task. You can pass parameters into a function. It helps us to make our code more organized and manageable.
Functions are defined using the def keyword followed by the function name and optional parameters:
def greet(name): return f"Hello, {name}!"
To use a function, call it by its name and provide necessary arguments:
message = greet("Charlie") print(message) # Output: "Hello, Charlie!"
Functions can return values using the return statement:
def multiply(a, b): return a * b product = multiply(4, 6) print(product) # Output: 24
def greet(name): # 'name' is a parameter print(f"Hello, {name}!") greet("Alice") # "Alice" is an argument
def add(x, y): # 'x' and 'y' are parameters return x + y result = add(3, 5) # 3 and 5 are arguments print(result) # Output: 8
Therefore Parameters define what kind of data a function can accept, while arguments are the actual data passed to the function when called. This distinction allows functions to be versatile and reusable in Python programming.
This section outlines different techniques for importing modules in Python:
Simple Import:
import module_name module_name.function_name()
Import with Alias:
import module_name as alias alias.function_name()
Import Specific Items:
from module_name import function_name, variable_name function_name()
Import All Items (Not Recommended):
from module_name import * function_name()
Conditional Import:
if condition: import module_name else: import alternative_module as module_name
Dynamic Import:
module_name = __import__('module_name') module_name.function_name()
For more modules and advanced usage, explore additional resources online or search on Google.
File handling refers to reading or writing data from files. Python provides some functions that allow us to manipulate data in the files.
Open Function:
var_name = open("file name", " mode")
Modes:
r: to read the content from filew: to write the content into filea: to append the existing content into filer+: To read and write data into the file. The previous data in the file will be overridden.w+: To write and read data. It will override existing data.a+: To append and read data from the file. It wonโt override existing data.Close Function:
var_name.close()
Read Functions:
read(): returns one big stringreadlines(): returns a listreadline(): returns one line at a timeWrite Function:
write() # Used to write a fixed sequence of characters to a file
Example:
In Python, we have two ways to handle files. In the first way, we do not need to close the file we opened, but in the second way, we have to close the file we opened.
#1st way: with open('file.txt', 'w') as f: f.write("Hello, World!") #2nd way: var_name = open("file name", " mode") var_name.write("hello") var_name.close()
Exception handling in Python allows you to manage and respond to errors that may occur during program execution.
Syntax:
try: # Code that might raise an exception except ExceptionType1: # Handle ExceptionType1 except ExceptionType2: # Handle ExceptionType2 except ExceptionType3: # Handle ExceptionType3 else: # Optional else block # Executes if no exceptions were raised in the try block finally: # Optional finally block # Executes whether an exception occurred or not # Useful for cleanup actions like closing files or releasing resources
Types of Exception handling:
try: # Code that might raise different exceptions except ZeroDivisionError: # Handle division by zero error except IndexError: # Handle index out of range error except FileNotFoundError: # Handle file not found error except KeyError: # Handel Key errors
In Python, variables can have different scopes, primarily categorized into two main types: local and global.
Example:
def my_function(): # This is a local variable x = 10 print("Inside the function: x =", x) my_function()
In this example, x is a local variable within the my_function function. It can only be accessed and used within the function.
Example:
# This is a global variable y = 20 def my_function(): # Accessing the global variable within the function print("Inside the function: y =", y) my_function() # We can also access y outside the function print("Outside the function: y =", y)
In this example, y is a global variable defined outside the function my_function. It can be accessed both inside and outside the function without any issues.
global Keyword:
global keyword to indicate that you are working with the global variable.Example:
z = 30 def modify_global_variable(): global z # Use the 'global' keyword to modify the global variable z = 40 modify_global_variable() print("Modified global variable z =", z)
In this example, the global keyword is used inside the modify_global_variable function to modify the global variable z. As a result, the value of z is changed to 40.
It is a programming approach that primarily focuses on using objects and classes. The objects can be any real-world entities.
.png)
Aaryacode19/Python-Cheatsheet is a public repo on GitHub by Aaryacode19. Python, created by Guido van Rossum and first released in 1991, is widely used in web development, data science, AI, and more. Refer to this Python cheatsheet by Aarya for a quick guide.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2024-12-17. Take My Repo does not judge from that whether it is maintained.

Jupyter notebooks in Russian. Introduction to Python, basic algorithms and data structures
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
A list of useful payloads and bypass for Web Application Security and Pentest/CTF
Easy, fast, transparent generic derivation of typeclass instances

All-inclusive Javascript cheatsheet, Playground, and Visualization
Master the technique of confidently writing robust C++ code
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/Aaryacode19/Python-CheatsheetTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.
