-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstrings.py
More file actions
43 lines (30 loc) · 799 Bytes
/
strings.py
File metadata and controls
43 lines (30 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# Zur Bedeutung von `print` siehe Ein_Ausgabe.py
ein = "Dies ist ein einzeiliger String." # type: str
print(ein)
mehr = """
Dies ist ein mehrzeiliger String.
Leerzeilen, Zeilenumbrüche und Einrückung
werden mit in den String übernommen.
""" # type: str
print(mehr)
f = "foo"
b = "bar"
# Operatoren auf Strings anwenden:
# (für mehr Informationen siehe die Wiki-Seite zu Operatoren)
print(f + b)
print(5 * f)
print(5 * (f + " "))
# Daten anderer Typen in Strings umwandeln:
s = str(5)
print(s)
# Groß- und Kleinschreibung:
h = "haMSter"
# Alle Buchstaben groß:
print(h.upper()) # OUT: HAMSTER
# Alle Buchstaben klein:
print(h.lower()) # OUT: hamster
# Den ersten Buchstaben groß:
print(h.capitalize()) # OUT: Hamster
# Länge
print(len(h)) # OUT: 7