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

Python Cheat Sheet Expanded

This document provides a cheat sheet for Python programming, covering basic syntax, data types, operators, control statements, loops, functions, object-oriented programming, exception handling, file handling, and important modules. Key examples are included for each topic, such as printing to the console, defining functions, and handling exceptions. The cheat sheet serves as a quick reference for essential Python concepts and functionalities.

Uploaded by

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

Python Cheat Sheet Expanded

This document provides a cheat sheet for Python programming, covering basic syntax, data types, operators, control statements, loops, functions, object-oriented programming, exception handling, file handling, and important modules. Key examples are included for each topic, such as printing to the console, defining functions, and handling exceptions. The cheat sheet serves as a quick reference for essential Python concepts and functionalities.

Uploaded by

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

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

You might also like