This contains relevant lines of codes and commands as well as examples for the material of Introduction to Python. This summary does not include theoretical or conceptual parts. This document might be especially useful because it is an allowed exam material, i.e. one can use it during the exam and ...
→ substring = what should be found !r = string with “ “
Start, end → index positions Datetime f – string:
i.e. i.e. print(f” Today is {today: %B, %d, %y}”)
for i in x: in-line function like lambda:
try:
print(i.find(….)) num1 = …
except Value Error:
print(…) num2 = …
print(f”{num1} plus {num2} is {num1 + num2}”)
Print words on separate lines:
or with functions:
X=“…“
def main(num1, num2)
for word in x.split():
return num1 + num2
print(x)
print(f” … is {main(10, 20}”)
String Formatting:
Template method
Positional Formatting:
from string import Template
“text { } “.format(values to be included)
→ using $ as placeholder
print(“ text { } … .format(string1, string2 …)”)
(1) Create template
with index:
→ string1 = Template(“… $identifier .. “)
print(“ {index 1} … {index 2..}”.format(strings1 ..)”)
(2) Fill identifier variable
Placeholders with dictionary:
→ string1.substitute(identifier=”…..”)
dict1 = {key1: value1, key2: value2}
Use ${identifier} when elements are directly on
print(“{data[key1]} … “.format(data = dict1))
string1.safe_substitute(…) → only fills where
specify inside placeholder which format
possible, unfilled identifiers are unchanged
→ {index: format}
i=…
f – strings:
i.isnumeric() → if True then ..
f”literal string {expression}
print(f” …. {expression1} …)
here als {expression: format}
format → d = digit (integer)
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller mathiasm1. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $4.32. You're not tied to anything after your purchase.