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

Python Cheat Sheet Updated

This Python cheat sheet covers basic syntax, data types, and control structures such as conditionals and loops. It includes operations for lists, strings, and dictionaries, as well as function definitions and file handling methods. Additionally, it provides an overview of basic Pandas and NumPy operations for data manipulation.

Uploaded by

bcampbell16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Cheat Sheet Updated

This Python cheat sheet covers basic syntax, data types, and control structures such as conditionals and loops. It includes operations for lists, strings, and dictionaries, as well as function definitions and file handling methods. Additionally, it provides an overview of basic Pandas and NumPy operations for data manipulation.

Uploaded by

bcampbell16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Cheat Sheet

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.

You might also like