Python_Programming_Course
Python_Programming_Course
==================================================
print("Hello, World!")
print("Welcome,", name)
Example:
age = 18
price = 99.99
==================================================
marks = 85
print("Grade: A")
elif marks >= 75:
print("Grade: B")
else:
print("Grade: C")
num = 29
is_prime = True
if num % i == 0:
is_prime = False
break
==================================================
fruits.append("orange")
#3.2 Dictionaries
Example:
#3.3 Sets
Example:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
Module 4: Functions
#4.1 Defining Functions
Example:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
square = lambda x: x ** 2
print(square(4)) # Output: 16
==================================================
==================================================
try:
result = 10 / 0
except ZeroDivisionError:
finally:
print("Execution complete.")
==================================================
class Rectangle:
self.length = length
self.width = width
def area(self):
rect = Rectangle(5, 3)
print(rect.area()) # Output: 15
==================================================
Example:
print("Found!")
#8.2 Efficient Loops
- Prefer list comprehensions.
Example:
==================================================
return a + b
return a - b
questions = {
score = 0
for q, a in questions.items():
user_ans = input(q)
if user_ans == a:
score += 1
==================================================
Module 10: Advanced Topics (Optional)
#10.1 Libraries (NumPy, Pandas)
Example (Pandas):
import pandas as pd
df = pd.DataFrame(data)
print(df)
if arr[mid] == target:
return mid
low = mid + 1
else:
high = mid - 1
return -1
==================================================