# Python - High-level, interpreted programming language

"""
Python is a high-level, interpreted programming language known for its simplicity and readability.
Created by Guido van Rossum and first released in 1991, Python emphasizes code readability
with its notable use of significant whitespace. It supports multiple programming paradigms,
including procedural, object-oriented, and functional programming.

Key Features:
- Easy to learn and use
- Interpreted language
- Dynamically typed
- Extensive standard library
- Cross-platform compatibility
- Strong community support
"""

# Variables and Data Types
name = "Python"
version = 3.11
is_interpreted = True
features = ["simple", "readable", "versatile"]

# Print function
print(f"Welcome to {name} {version}!")

# Control Structures
if is_interpreted:
    print("Python is an interpreted language")

# Loops
for i, feature in enumerate(features):
    print(f"Feature {i+1}: {feature}")

# Functions
def greet(name):
    return f"Hello, {name}!"

print(greet("Programmer"))

# Classes and Objects
class Animal:
    def __init__(self, name):
        self.name = name
    
    def speak(self):
        pass

class Dog(Animal):
    def speak(self):
        return f"{self.name} says Woof!"

dog = Dog("Buddy")
print(dog.speak())

# List comprehensions
squares = [x**2 for x in range(10)]
print("Squares:", squares)

# Exception handling
try:
    result = 10 / 0
except ZeroDivisionError:
    print("Cannot divide by zero!")

# Lambda functions
add = lambda x, y: x + y
print("5 + 3 =", add(5, 3))

# File operations
with open("sample.txt", "w") as file:
    file.write("This is a sample file created with Python")

print("Python demo completed!")

更多推荐