Learn coding with amol
Hello my name is amol sharma or vineet and this is my fourth part of learn coding with amol and in this part we are going to learn python.
PART-4 python.
π Complete Python Guide
This guide includes all important Python concepts with examples.
1. Variables
Variables store values that can be used later in the program.
name = "Amol"
age = 13
height = 5.6
2. Data Types
Common types include int, float, string, list, dict, bool.
x = 10 # int
y = 3.14 # float
name = "Amol" # str
items = [1, 2, 3] # list
person = {"name": "Amol", "age": 13} # dict
is_human = True # bool
3. if / elif / else
Decision-making in Python.
score = 85
if score >= 90:
print("Excellent")
elif score >= 50:
print("Passed")
else:
print("Failed")
4. Loops
Repeat code using for or while loops.
for i in range(5):
print("Count:", i)
i = 0
while i < 3:
print("Hi")
i += 1
5. Functions
Reusable blocks of code defined with def.
def greet(name):
print("Hello", name)
greet("Amol")
6. Lists
Ordered collections of items.
fruits = ["apple", "banana", "mango"]
print(fruits[0]) # apple
fruits.append("orange")
7. Dictionaries
Store data in key-value pairs.
user = {"name": "Amol", "age": 13}
print(user["name"]) # Amol
8. Classes and Objects
Blueprints for creating objects.
class Person:
def __init__(self, name):
self.name = name
def greet(self):
print("Hi, I am", self.name)
p = Person("Amol")
p.greet()
9. Import Modules
Use built-in or external Python modules.
import math
print(math.sqrt(16))
print(math.pi)
10. File Handling
Read and write text files in Python.
# Write to file
with open("data.txt", "w") as f:
f.write("Hello, file!")
# Read from file
with open("data.txt", "r") as f:
print(f.read())

Comments
Post a Comment