Learn Python 1hour Notes Fixed
Learn Python 1hour Notes Fixed
1. Basics
Print something:
print("Hello, World!")
Variables:
x=5
name = "Alice"
Data Types:
- int (5), float (5.5), str ("hello"), bool (True/False), list, dict, tuple, set
2. Conditions
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
3. Loops
For loop:
for i in range(5):
print(i)
While loop:
while x > 0:
Learn Python in 1 Hour - Quick Notes
print(x)
x -= 1
4. Functions
def greet(name):
print(greet("Alice"))
5. Lists
fruits.append("orange")
print(fruit)
6. Dictionaries
print(person["name"])
7. Importing Modules
import math
print(math.sqrt(16))
Learn Python in 1 Hour - Quick Notes
class Person:
self.name = name
def greet(self):
p = Person("Alice")
p.greet()
9. Error Handling
try:
except ValueError:
Writing to file:
f.write("Hello, file!")
Reading file:
content = f.read()
print(content)
Bonus Tips
Learn Python in 1 Hour - Quick Notes