Introduction to Python Programming - Class Notes
Introduction to Python Programming
1. What is Python?
Python is a high-level, interpreted programming language known for its readability and broad
applicability in web development, data analysis, automation, AI, and more.
2. Setting Up Python
- Download and install Python from python.org
- Use an IDE like VS Code, PyCharm, or Jupyter Notebook
3. Basic Syntax
# Print statement
print("Hello, World!")
# Variables
x=5
name = "Alice"
4. Data Types
- int: 10
- float: 3.14
- str: "Hello"
- bool: True/False
- list, tuple, dict
5. Control Flow
# Conditional Statements
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
# Loops
for i in range(5):
print(i)
while x > 0:
x -= 1
6. Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
7. File Handling
with open("example.txt", "w") as file:
file.write("This is a file.")
8. Libraries and Modules
import math
print(math.sqrt(16))
9. Error Handling
try:
print(10 / 0)
except ZeroDivisionError:
print("Cannot divide by zero!")
10. Conclusion
Python is a powerful, easy-to-learn language that's great for beginners and professionals alike.
End of Notes