Frequently Asked Questions about Python (FAQ)
In this section, you’ll find a complete Python FAQ, designed for beginners and intermediate/advanced developers. We’ve gathered the most common questions and answered them with examples, practical tips, and links to other DJC tutorials.
Basic Python Questions
What is Python?
Python is an interpreted, high-level, general-purpose programming language. It’s known for its simple syntax and “readability first” philosophy. It’s used in web development, data science, artificial intelligence, automation, and more.
Why is it called Python?
Its creator, Guido van Rossum, named it after the British comedy group Monty Python’s Flying Circus, not the snake.
Is Python free?
Yes. Python is open source, licensed under the PSF (Python Software Foundation), and can be used in personal or commercial projects.
How do I install Python?
Download it from the official website python.org. On Linux and macOS systems, Python often comes pre-installed. To check:
python --version
Is Python easy to learn?
Yes. It’s one of the most recommended languages for beginners thanks to its clear syntax and large community.
Intermediate Python Questions
Difference between list, tuple, and set
- List (
list
): ordered, mutable, allows duplicates. - Tuple (
tuple
): ordered, immutable. - Set (
set
): unordered, no duplicates.
lista = [1, 2, 2, 3]
tupla = (1, 2, 3)
conjunto = {1, 2, 3}
What is a dictionary in Python?
A dict
stores data as key:value pairs.
persona = {"nombre": "Ana", "edad": 25}
print(persona["nombre"]) # Ana
What is indentation and why does it matter?
Python uses spaces or tabs to structure code. Correct example:
if True:
print("Correct")
What are args and *kwargs?
*args
: receives variable-length positional arguments as a tuple.**kwargs
: receives keyword arguments as a dictionary.
def example(*args, **kwargs):
print(args)
print(kwargs)
example(1, 2, name="Ana", age=30)
What is a class in Python?
Classes allow Object-Oriented Programming (OOP).
class Person:
def __init__(self, name):
self.name = name
p = Person("John")
print(p.name)
How to start a basic HTTP web server with Python?
Python lets you start a basic HTTP server with a single command using the built-in http.server
module.
From the terminal
python -m http.server 8000
8000
is the port (you can change it, e.g., to 8080).- It will serve files from the directory where you run the command.
- Access in the browser:
http://localhost:8000
Serving a specific folder
python -m http.server 8000 --directory /path/to/your/folder
Using a Python script
from http.server import SimpleHTTPRequestHandler, HTTPServer
port = 8000
server = HTTPServer(("0.0.0.0", port), SimpleHTTPRequestHandler)
print(f"Server running at http://localhost:{port}")
server.serve_forever()
"0.0.0.0"
allows other devices on the local network to access it.
SimpleHTTPRequestHandler
serves static files from the current directory.
Important notes
- This server is only for local testing, not secure for production.
- For real environments, use frameworks such as Flask, Django, or FastAPI with servers like Gunicorn or Uvicorn.
Advanced Python Questions
What are decorators in Python?
A decorator is a function that modifies the behavior of another function.
def decorator(func):
def wrapper():
print("Before")
func()
print("After")
return wrapper
@decorator
def greet():
print("Hello")
greet()
What is the LEGB rule in Python?
It defines the order in which variables are searched:
- Local
- Enclosing (nested functions)
- Global
- Built-in
How does Python manage memory?
Python uses a dynamic memory manager and a garbage collector that removes unused objects automatically.
What does “Batteries Included” mean?
It’s a Python philosophy: it comes with a large standard library ready to use (modules for files, JSON, web, databases, and more).
This Python FAQ gathers the most common questions from basic to advanced topics. The goal is to always provide a clear, concise answer with practical examples.
More questions will be added soon. In the meantime, check out the Step-by-Step Python Tutorial.