Python Cheat Sheet Expanded
Python Cheat Sheet Expanded
1. Basic Syntax
print("Hello, World!")
2. Data Types
3. Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
== Equal to
!= Not equal to
>= Greater than or equal to
<= Less than or equal to
4. Control Statements
if condition:
# code block
elif another_condition:
# another code block
else:
# default block
Java Cheat Sheet
5. Loops
for i in range(10):
print(i)
while condition:
# loop body
6. Functions
class Animal:
def __init__(self, name):
self.name = name
def make_sound(self):
print("Sound")
class Dog(Animal):
def make_sound(self):
print("Bark")
8. Exception Handling
try:
x = 10 / 0
except ZeroDivisionError as e:
print("Error:", e)
9. File Handling