PYTHON Tutorial
Python is a high-level programming language known for its readability and simplicity. Let's break down the key concepts and syntax:
my_name = "John"
if
statements evaluate conditions and execute code if True.elif
and else
clauses provide alternative paths.if my_age > 18:
print("You are an adult.")
elif my_age < 18:
print("You are a minor.")
else:
print("You are 18 years old.")
for
loops iterate over sequences.while
loops execute until a condition becomes False.for item in my_list:
print(item)
def
keyword.def greet(name):
print("Hello, " + name)
greet("John")
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
person1 = Person("John", 30)
print(person1.name) # Prints "John"
# Create a variable
my_name = "John"
# Print the variable
print("Hello, " + my_name)
# Check if the name is "John"
if my_name == "John":
print("You are John!")