Skip to content

Instantly share code, notes, and snippets.

@balu
Created January 15, 2021 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balu/33b1b1f00187724a0a59745fab487a6e to your computer and use it in GitHub Desktop.
Save balu/33b1b1f00187724a0a59745fab487a6e to your computer and use it in GitHub Desktop.

Some examples that illustrate f-strings in python.

Everything that follows a '#' upto next line is ignored by python. These are called comments.

print(f"A normal string.") # Same as print("A normal string.")

# Lets do a sum and show its result in a pretty fashion.
I = 0.6
V = 12.0
R = V/I
print(f"R = {V}/{I} = {R}\u03a9") # prints R = 12.0/0.6 = 20.0Ω

print(f"{z}") # NameError: name 'z' is not defined

print("{z}") # prints {z}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment