Python is a versatile, high-level programming language that is easy to learn and widely used for web development, data analysis, artificial intelligence, and more!
A simple Python program:
# Hello World Program
print("Hello, World!")
Examples of different data types:
# Integer
x = 10
# Float
y = 3.14
# String
name = "Python"
# List
fruits = ["apple", "banana", "cherry"]
# Dictionary
person = {"name": "Alice", "age": 25}
Conditional statements and loops:
# If-else statement
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
# For loop
for fruit in fruits:
print(fruit)
# While loop
count = 0
while count < 5:
print(count)
count += 1
Defining and calling functions:
# Function definition
def greet(name):
return f"Hello, {name}!"
# Function call
print(greet("Alice"))
Using libraries in Python:
# Importing a module
import math
# Using a function from the module
result = math.sqrt(16)
print(result)