All questions
Showing of 59What is the difference between Python 2 and Python 3?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Python 3 is a backward-incompatible redesign of the language, so most Python 2 code needs changes to run on it. Python 2 reached its end of life on January 1, 2020, and new projects use Python 3.
The main differences are:
printbecame a function, so you writeprint("hello")instead ofprint "hello".- Strings are Unicode text by default, and raw bytes have their own
bytestype. - The
/operator does true division, so5/2returns2.5where Python 2 returned2. Use//for floor division. range()returns a lazy range object instead of a list, andmap()andfilter()return iterators.raw_input()was renamed toinput(), which always returns a string.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is PEP 8?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
PEP 8 is the official style guide for Python code. It sets shared conventions so that code from different people looks the same. Its main rules are:
- Indent with 4 spaces per level.
- Keep lines to a maximum of 79 characters.
- Name variables and functions in
snake_case, classes inCapWords, and constants inUPPER_CASE. - Group imports in order: standard library, third-party packages, then your own modules.
- Put single spaces around operators and after commas.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain Python's indentation and why it matters.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Python uses indentation to mark code blocks, where languages such as C and Java use braces {}. All lines in one block start at the same indentation level, and a deeper level opens a nested block. The parser reads this whitespace, so the layout is part of the syntax.
if x > 0:
print("Positive") # 4 spaces indentation
if x > 10:
print("Greater than 10") # 8 spaces indentation
else:
print("Non-positive")
It matters for two reasons. It gives every Python file the same consistent shape, which makes code easier to read. It also means a wrong indent either moves a line into a different block or stops the file from running. Incorrect indentation raises IndentationError, and mixing tabs and spaces inconsistently raises TabError. PEP 8 recommends four spaces per level.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are Python keywords and identifiers?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Keywords are reserved words with a fixed meaning in the language, such as if, def and class. You cannot use them as names. Identifiers are the names you choose for variables, functions and classes. An identifier follows these rules:
- It starts with a letter or an underscore.
- It contains only letters, digits and underscores.
- It is case-sensitive, so
countandCountare different names. - It cannot be a keyword.
# Valid identifiers
variable_name = 10
_private_var = 20
ClassName = "example"
# Invalid identifiers
# 123variable = 10 # Cannot start with digit
# class = "test" # Cannot use keyword
The keyword module lists every keyword in keyword.kwlist. A few names, such as match and case, are soft keywords, reserved only inside the statements that use them.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain Python's built-in data types.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Python's most common built-in data types, grouped by the kind of value they hold, are:
- Numeric:
int,floatandcomplex. - Sequence:
str,listandtuple. - Set:
setandfrozenset. - Mapping:
dict. - Boolean:
bool, with the valuesTrueandFalse. - None:
NoneType, whose only value isNone.
Python is dynamically typed, so a variable has no fixed type, and type(value) tells you the type of the value it holds. The types also differ in mutability. Lists, dicts and sets can change in place, while numbers, strings and tuples cannot.
integer = 42
floating = 3.14
string = "Hello"
boolean = True
none_value = None
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between list and tuple?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A list is mutable, so you can add, remove and change its items after you create it. A tuple is immutable, so its contents are fixed once it exists. Use a list for a collection that grows or changes, and a tuple for a fixed group of values, such as a pair of coordinates.
| List | Tuple |
|---|---|
| Mutable | Immutable |
Uses square brackets [] |
Uses parentheses () |
| Slower performance | Faster performance |
| More memory usage | Less memory usage |
A tuple is a little faster and smaller because Python allocates it once at a fixed size. A list keeps spare room so appends stay cheap. Because a tuple is immutable, it is also hashable when all its items are, so it can be a dictionary key or a set member. A list cannot.
# List - mutable
my_list = [1, 2, 3]
my_list[0] = 10 # Works
# Tuple - immutable
my_tuple = (1, 2, 3)
# my_tuple[0] = 10 # TypeError
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain Python dictionaries and their characteristics.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A dictionary is a mutable mapping from unique keys to values. It is built on a hash table, so looking up a value by its key takes O(1) time on average. Its main characteristics are:
- Keys must be unique and hashable, which means their hash value never changes. Strings, numbers and tuples of hashable items work as keys, but lists do not.
- Values can be any object.
- Since Python 3.7, a dictionary keeps its items in insertion order.
d[key]raisesKeyErrorfor a missing key, whiled.get(key)returnsNoneor a default you pass.
student = {
"name": "John",
"age": 25,
"grades": [85, 90, 78]
}
# Accessing values
print(student["name"]) # John
print(student.get("age")) # 25
# Adding/updating
student["email"] = "john@email.com"
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the different types of loops in Python.
What are break, continue, and pass statements?
Explain conditional statements in Python.
How do you define and call functions in Python?
Explain classes and objects in Python.
Explain exception handling in Python.
What is the difference between except and finally?
What is the difference between modules and packages?
Explain different ways to import modules.
What is the difference between range() and xrange()?
What are Python's built-in functions you should know?
Explain Python's __name__ == "__main__" idiom.
Explain Python's file handling modes.
What is the difference between is and == with examples?
What is the difference between mutable and immutable types in Python?
Explain list comprehensions in Python.
What is the difference between local and global variables?
Explain lambda functions in Python.
What is inheritance and how is it implemented?
Explain different types of function arguments.
Explain method overriding and method overloading.
What are class variables vs instance variables?
Explain encapsulation and access modifiers.
How do you raise custom exceptions?
What is __init__.py and what is its purpose?
What are decorators and how do they work?
Explain generators and the yield keyword.
Explain context managers and the with statement.
Explain the *args and **kwargs concepts.
How does Python manage memory?
What is the difference between del and garbage collection?
How can you improve Python performance?
Explain the difference between multiprocessing and multithreading.
What is unit testing and how is it implemented in Python?
Explain debugging techniques in Python.
What is the difference between assert and exception handling?
What is the difference between shallow copy and deep copy?
What are dataclasses and how do they work?
Explain the super() function.
What are Python's special or magic methods?
What are Python virtual environments and why are they important?
Why are mutable default arguments dangerous in Python?
What is the difference between instance methods, class methods and static methods?
What is the difference between an iterable and an iterator?
What is a closure in Python?
Does Python pass arguments by value or by reference?
What happens when you run a Python program?
Explain the concept of monkey patching.
What are metaclasses in Python?
Explain Python's memory optimization techniques.
What is the Global Interpreter Lock (GIL)?
Explain Python's async/await and asynchronous programming.
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Python in pictures.
A quick recap of Python in 31 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.
Pro The first chapter is free to play. The other 27 pictures come with Pro.
Python cheatsheet
- Names & objects01
- Types & collections02
- Syntax, style & loops03
- Functions & decorators04
- Iterators & generators05
- Classes & OOP06
- Errors, cleanup & testing07
- Modules, files & venvs08
- Memory & performance09
- Threads, processes & async10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 27 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in52 of 59 Python answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.