Python is a high-level, interpreted programming language known for its readability and versatility. It is used in various fields like web development, data analysis, artificial intelligence, and more.
print("Hello, World!")
Learn the basic syntax and structure of Python programming.
# This is a comment
number = 42
print(f"The number is: {number}")
Python supports various data types including integers, floats, strings, and booleans.
age = 25 # Integer
price = 99.99 # Float
grade = 'A' # String
is_student = True # Boolean
Control flow statements allow you to control the execution flow of your program.
number = 10
if number > 0:
print("Positive number")
elif number < 0:
print("Negative number")
else:
print("Zero")
# Loop example
for i in range(5):
print(i)
Functions are reusable blocks of code that can take inputs and return outputs.
def add(a, b):
return a + b
result = add(5, 3) # result = 8
Python is an object-oriented programming language that allows you to define classes and create objects.
class Student:
def __init__(self, name, age):
self.name = name
self.age = age
def display(self):
print(f"Name: {self.name}")
print(f"Age: {self.age}")
student = Student("John", 21)
student.display()