pyodide: loading…

[concept]Python Basics

Variables & F-Strings

# theory

Variables hold values. Python figures out the type:

name = "Alice"
age = 25
price = 19.99
is_active = True

F-strings embed expressions inside strings. Prefix with f, put expressions in {}:

print(f"hi {name}, you are {age} years old")
print(f"total: ${price * 3:.2f}")  # math works inside braces

:.2f is a format spec. A few you'll reach for constantly:

  • :.2f two decimals (3.14159 becomes 3.14)
  • :, thousands separator (1000000 becomes 1,000,000)
  • :.0% percent (0.85 becomes 85%)
  • :>10 right-align inside 10 chars

# examples [3]

# example 01 · basic variables

Creating different types of variables and printing them

1
2
3
4
5
6
7
8
9
🐍
Loading PythonSetting up pandas & numpy...
# example 02 · calculations in f-strings

You can do math right inside the curly braces

1
2
3
4
5
6
7
8
9
10
11
🐍
Loading PythonSetting up pandas & numpy...
# example 03 · string methods with variables

Variables can be modified with string methods

1
2
3
4
5
6
7
8
9
🐍
Loading PythonSetting up pandas & numpy...

# challenges [2]

# challenge 01/02todo
Create a variable called 'product' with value 'Laptop' and 'price' with value 999.99. Print them in an f-string like: 'The Laptop costs $999.99'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
🐍
Loading PythonSetting up pandas & numpy...
# challenge 02/02todo
Create variables for hours=40 and rate=25.50. Calculate and print the weekly pay formatted as currency with 2 decimal places.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
🐍
Loading PythonSetting up pandas & numpy...

# project

# project-challenge

thread: SF Permits Analysis · reward: 50 xp

# brief

You're building a permit lookup system. Given a permit number and its details, create a formatted summary line that displays the key information clearly.

# task

Format Permit Summary

# your code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
🐍
Loading PythonSetting up pandas & numpy...