0 day streak
Code library

Code worth reading.

Hand-picked snippets across TypeScript, Python, Rust, Go, and more — each one comes with a line-by-line breakdown so you can read it like the people who wrote it.

3495 snippets · 10 languages
▶ Start learning
Python · BeginnerSnippet

Conditional Logic

If-statements allow your code to make decisions. The elif (else if) and else clauses provide alternative paths based on different conditions.

snippet.py
python
1
2
3
4
5
6
7
score = 85
if score >= 90:
print("Excellent!")
elif score >= 70:
print("Good job!")
else:
print("Keep practicing!")
Control Flow
Python · BeginnerSnippet

Basic Exception Handling

Exception handling prevents your program from crashing when errors occur. The try block contains code that might fail, while the except block handles the error.

snippet.py
python
1
2
3
4
try:
number = int("abc")
except ValueError:
print("That is not a valid number!")
Error Handling
Python · BeginnerSnippet

Defining Functions

Functions are reusable blocks of code. They can take inputs (parameters) and return a result using the return keyword.

snippet.py
python
1
2
3
4
5
def calculate_area(width, height):
return width * height
result = calculate_area(5, 10)
print(f"Area: {result}")
Functions
Python · BeginnerSnippet

List Operations

Lists are ordered collections of items. You can add items using the .append() method and access them using their zero-based index.

snippet.py
python
1
2
3
4
tools = ["IDE", "Terminal"]
tools.append("Debugger")
first_tool = tools[0]
print(f"Using: {first_tool}")
Data TypesArrays & Lists
Python · BeginnerSnippet

Variable Assignment and f-Strings

In Python, variables are created by assigning a value. f-strings (formatted string literals) allow you to embed variables directly inside strings using curly braces.

snippet.py
python
1
2
3
name = "Python"
version = 3.12
print(f"Welcome to {name} version {version}!")
SyntaxData Types
Python · BeginnerSnippet

Python Dictionaries

Dictionaries store data in key-value pairs, allowing you to look up information using a specific label instead of an index.

snippet.py
python
1
user_data = {"username": "dev_pro", "level": 10}
SyntaxData Types
Python · BeginnerSnippet

The While Loop

A while loop repeatedly executes a block of code as long as a specified condition remains true.

snippet.py
python
1
2
3
4
counter = 0
while counter < 3:
print(counter)
counter += 1
SyntaxControl Flow
Python · BeginnerSnippet

Importing Modules

The import statement allows you to use code from external libraries or modules, such as the built-in math module for calculations.

snippet.py
python
1
2
3
import math
result = math.sqrt(16)
print(result)
SyntaxBest Practices