what is python,quick 01-02-2024, 02:42 AM
#1
Python is a versatile and high-level programming language known for its readability and simplicity. Here are some fundamental concepts:
Variables and Data Types:
python
message = "Hello, Python!"
age = 25
pi = 3.14
Control Structures:
python
if age < 18:
print("You are a minor.")
elif age >= 18 and age < 60:
print("You are an adult.")
else:
print("You are a senior citizen.")
Loops:
python
for i in range(5):
print(i)
while age < 30:
print("Still young!")
age += 1
Functions:
python
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Lists and Dictionaries:
python
my_list = [1, 2, 3, 4, 5]
my_dict = {"name": "John", "age": 30}
File Handling:
python
with open("example.txt", "r") as file:
content = file.read()
Exception Handling:
python
try:
result = 10 / 0
except ZeroDivisionError as e:
print(f"Error: {e}")
Variables and Data Types:
python
message = "Hello, Python!"
age = 25
pi = 3.14
Control Structures:
python
if age < 18:
print("You are a minor.")
elif age >= 18 and age < 60:
print("You are an adult.")
else:
print("You are a senior citizen.")
Loops:
python
for i in range(5):
print(i)
while age < 30:
print("Still young!")
age += 1
Functions:
python
def greet(name):
print(f"Hello, {name}!")
greet("Alice")
Lists and Dictionaries:
python
my_list = [1, 2, 3, 4, 5]
my_dict = {"name": "John", "age": 30}
File Handling:
python
with open("example.txt", "r") as file:
content = file.read()
Exception Handling:
python
try:
result = 10 / 0
except ZeroDivisionError as e:
print(f"Error: {e}")