Cheat Sheet
Cheat Sheet
Package/
Description Code Example
Method
Syntax:
1. 1
1. concatenated_string = string1
+ string2
Copied!
Concatenation Combines (concatenates) strings. Example:
1. 1
John"</td>
Copied!
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
9. 9
10. 10
1. x=7
2. # Integer Value
3. y=12.4
4. # Float Value
5. is_valid = True
6. # Boolean Value
7. is_valid = False
8. # Boolean Value
9. F_Name = "John"
Example:
1. 1
Accesses character at a specific 2. 2
Indexing
index.
1. my_string="Hello"
2. char = my_string[0]
Copied!
Syntax:
1. 1
1. len(string_name)
Copied!
Example:
len() Returns the length of a string.
1. 1
2. 2
1. my_string="Hello"
2. length = len(my_string)
Copied!
Example:
1. 1
2. 2
lower() Converts string to lowercase. 1. my_string="Hello"
2. uppercase_text =
my_string.lower()
Copied!
Example:
1. 1
Prints the message or variable inside 2. 2
print()
`()`.
1. print("Hello, world")
2. print(a+b)
Copied!
Example:
1. 1
2. 2
3. 3
4. 4
5. 5
- Addition (+): Adds two values 6. 6
together.
- Subtraction (-): Subtracts one value 7. 7
from another.
- Multiplication (*): Multiplies two 1. x = 9 y = 4
values.
2. result_add= x + y # Addition
Python Operators - Division (/): Divides one value by
another, returns a float. 3. result_sub= x - y #
- Floor Division (//): Divides one value
by another, returns the quotient as an Subtraction
integer.
- Modulo (%): Returns the remainder 4. result_mul= x * y #
after division. Multiplication
5. result_div= x / y # Division
6. result_fdiv= x // y # Floor
Division
7. result_mod= x % y #
Modulo</td>
Copied!
1. 1
2. 2
1. my_string="Hello"
2. new_text =
my_string.replace("Hello",
"Hi")
Copied!
Syntax:
1. 1
1. substring =
string_name[start:end]
Copied!
Slicing Extracts a portion of the string. Example:
1. 1
1. my_string="Hello" substring =
my_string[0:5]
Copied!
Example:
1. 1
2. 2
Splits string into a list based on a
split() 1. my_string="Hello"
delimiter.
2. split_text =
my_string.split(",")
Copied!
Example:
1. 1
2. 2
strip() Removes leading/trailing whitespace.
1. my_string="Hello"
2. trimmed = my_string.strip()
Copied!
1. 1
2. 2
1. my_string="Hello"
2. uppercase_text =
my_string.upper()
Copied!
Syntax:
1. 1
1. variable_name = value
Copied!
Example:
Variable 1. 1
Assigns a value to a variable.
Assignment
2. 2
to variable name
2. x = 5 # assigning 5 to
variable x
Copied!