Python Cheat Sheet Updated
Python Cheat Sheet Updated
Basic Syntax
Variables, Data Types (int, float, str, list, dict, set, tuple), Conditionals (if-elif-else), Loops (for, while).
List Operations
append() - Adds an element to the end of the list.
extend() - Adds elements from another list.
insert() - Inserts an element at a specified position.
remove() - Removes the first occurrence of a value.
pop() - Removes an element by index.
String Methods
upper() - Converts a string to uppercase.
lower() - Converts a string to lowercase.
split() - Splits a string into a list.
join() - Joins a list into a string.
replace() - Replaces occurrences of a substring.
Dictionary Methods
keys() - Returns all keys.
values() - Returns all values.
items() - Returns all key-value pairs.
get() - Retrieves a value by key.
Functions
def function_name(parameters): return value - Defines a function.
File Handling
open('file.txt', 'r') - Opens a file in read mode.
read() - Reads file content.
write() - Writes content to a file.
close() - Closes the file.
Pandas Basics
df.head() - Displays the first rows of a DataFrame.
df.tail() - Displays the last rows of a DataFrame.
df.describe() - Shows summary statistics.
df.info() - Displays DataFrame info.
NumPy Operations
np.array() - Creates a NumPy array.
np.zeros() - Creates an array of zeros.
np.ones() - Creates an array of ones.
np.mean() - Computes the mean.