Python Basics: Unterschied zwischen den Versionen
Aus MattWiki
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…“) |
Matt (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
This article contains my notes on the Python programming language as of Python 3.x. | This article contains my notes on the Python programming language as of Python 3.x. | ||
== Operators == | |||
https://www.codecademy.com/resources/docs/python/operators | |||
https://docs.python.org/3/reference/lexical_analysis.html#operators | |||
== Strings == | == Strings == | ||
Zeile 25: | Zeile 30: | ||
# equivalent to: | # equivalent to: | ||
print("We are doing a road trip from {} through {} to {}".format(a, b, c)) | print("We are doing a road trip from {} through {} to {}".format(a, b, c)) | ||
</syntaxhighlight>Further reading: https://realpython.com/python-string-formatting/ | </syntaxhighlight>Further reading: | ||
* https://realpython.com/python-string-formatting/ | |||
* https://docs.python.org/3/whatsnew/3.12.html#pep-701-syntactic-formalization-of-f-strings | |||
* https://docs.python.org/3/library/string.html#template-strings | |||
== Classes and Object Methods == | |||
https://docs.python.org/3/reference/datamodel.html#emulating-container-types | |||
[[Kategorie:Python]] | [[Kategorie:Python]] |
Version vom 30. November 2024, 20:49 Uhr
This article contains my notes on the Python programming language as of Python 3.x.
Operators
https://www.codecademy.com/resources/docs/python/operators
https://docs.python.org/3/reference/lexical_analysis.html#operators
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/
- https://docs.python.org/3/whatsnew/3.12.html#pep-701-syntactic-formalization-of-f-strings
- https://docs.python.org/3/library/string.html#template-strings
Classes and Object Methods
https://docs.python.org/3/reference/datamodel.html#emulating-container-types