python / beginner
Snippet
String Formatting with f-strings
F-strings provide a modern and readable way to embed variables directly into string literals using curly braces.
snippet.py
1
2
3
name = "Dev"message = f"Hello, {name}!"print(message)
Breakdown
1
name = "Dev"
Initialize a variable with a string value.
2
message = f"Hello, {name}!"
Create a formatted string that includes the value of the 'name' variable.