Python is a powerful, easy-to-learn programming language used in apps, AI, games, data science, automation, websites, and more.
print("Hello, Python!")
Variables store data. Python creates them automatically when you assign values.
x = 10 name = "Alex" pi = 3.14
Common Python data types:
If statements make decisions in programs.
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
Loops repeat code multiple times.
for i in range(5):
print(i)
x = 0
while x < 5:
print(x)
x += 1
Functions are reusable blocks of code.
def greet(name):
print("Hello", name)
greet("Alex")
fruits = ["apple", "banana", "orange"] print(fruits[0])
person = {"name": "Alex", "age": 15}
print(person["name"])
class Dog:
def __init__(self, name):
self.name = name
mydog = Dog("Buddy")
print(mydog.name)