Java Cheat Sheet
Python Cheat Sheet
1. Basic Syntax
print("Hello, World!")
2. Data Types
int - Integer (e.g., 10)
float - Floating point (e.g., 10.5)
bool - Boolean (True or False)
str - Text (e.g., "Hello")
list - Collection of values (e.g., [1,2,3])
dict - Key-value pairs (e.g., {'name': 'John', 'age': 30})
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
def add(a, b):
return a + b
7. Object-Oriented Programming (OOP)
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
with open("file.txt", "w") as file:
file.write("Hello, Python")
Java Cheat Sheet
10. Important Modules
import os # Operating system functions
import sys # System-specific parameters
import math # Mathematical functions
import random # Random number generation
import datetime # Date and time manipulation
import json # JSON data handling