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

Python-Class_test_Document

This document provides a concise overview of Python programming basics, including data types, data structures, control flow, functions, classes, file handling, and exception handling. Key concepts such as lists, tuples, sets, dictionaries, and the importance of indentation are highlighted. It serves as a quick reference for fundamental Python programming techniques and best practices.

Uploaded by

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

Python-Class_test_Document

This document provides a concise overview of Python programming basics, including data types, data structures, control flow, functions, classes, file handling, and exception handling. Key concepts such as lists, tuples, sets, dictionaries, and the importance of indentation are highlighted. It serves as a quick reference for fundamental Python programming techniques and best practices.

Uploaded by

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

🐍 Python Class Notes (One Page)

🔹 1. Python Basics

python

CopyEdit

print("Hello, World!") # Output text

name = "Alice" # String variable

age = 25 # Integer

pi = 3.14 # Float

is_active = True # Boolean

🔹 2. Data Structures

python

CopyEdit

# List

fruits = ["apple", "banana", "cherry"]

fruits.append("orange")

# Tuple (Immutable)

colors = ("red", "green", "blue")

# Set (Unique items)

nums = {1, 2, 3}

# Dictionary

person = {"name": "Alice", "age": 25}

🔹 3. Control Flow

python

CopyEdit
# If-else

if age >= 18:

print("Adult")

else:

print("Minor")

# Loops

for fruit in fruits:

print(fruit)

while age > 0:

age -= 1

🔹 4. Functions

python

CopyEdit

def greet(name):

return f"Hello, {name}"

print(greet("Bob"))

🔹 5. Classes & Objects

python

CopyEdit

class Person:

def __init__(self, name, age):

self.name = name

self.age = age
def greet(self):

print(f"Hi, I'm {self.name}")

p1 = Person("Alice", 30)

p1.greet()

🔹 6. File Handling

python

CopyEdit

with open("file.txt", "r") as f:

data = f.read()

🔹 7. Exception Handling

python

CopyEdit

try:

x=5/0

except ZeroDivisionError:

print("Cannot divide by zero!")

🔹 8. Useful Tips

 Indentation matters (use 4 spaces)

 Comments: # this is a comment

 Use pip install to add packages

You might also like