Python Basics

Aus MattWiki
Version vom 30. November 2024, 20:18 Uhr von Matt (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „This article contains my notes on the Python programming language as of Python 3.x. == Strings == === F-Strings === <syntaxhighlight lang="python3"> a = "Munich" b = "Frankfurt" c = "Berlin" # f-String print(f"We are doing a road trip from {a} through {b} to {c}") </syntaxhighlight> === Template Strings === <syntaxhighlight lang="python3"> a = "Munich" b = "Frankfurt" c = "Berlin" # Template string template = "We are doing a road trip from {} throug…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

This article contains my notes on the Python programming language as of Python 3.x.

Strings

F-Strings

a = "Munich"
b = "Frankfurt"
c = "Berlin"

# f-String
print(f"We are doing a road trip from {a} through {b} to {c}")

Template Strings

a = "Munich"
b = "Frankfurt"
c = "Berlin"

# Template string
template = "We are doing a road trip from {} through {} to {}"
print(template.format(a, b, c))
# equivalent to:
print("We are doing a road trip from {} through {} to {}".format(a, b, c))

Further reading: https://realpython.com/python-string-formatting/