Module 1

f-strings

A cleaner way to embed values in text.

Embedding values in text

Python offers a convenient way to put variables directly inside text. It is called an f-string. You put the letter f before the opening quote, and wrap variables in curly braces.

Pythonf-strings embed values directly.
sample = "Control"
temperature = 30
print(f"Sample: {sample}")print(f"Temperature: {temperature}")
Sample: Control Temperature: 30

The f tells Python to look for curly braces and replace them with the value of the variable inside. This is often cleaner than using commas.

Your task

Use an f-string

  • Create a variable name = "Python". Then use an f-string to print: Hello, Python!
Try it

Use f-strings when you want to build a sentence that includes variable values. They are very common in scientific programming.