capypad
0 day streak
python / beginner
Snippet

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}!")
Breakdown
1
name = "Python"
Assigns the string 'Python' to the variable name.
2
version = 3.12
Assigns a floating-point number to the variable version.
3
print(f"...")
Uses an f-string to print a formatted message to the console.