-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_strings.py
More file actions
52 lines (47 loc) · 1.5 KB
/
Copy pathmy_strings.py
File metadata and controls
52 lines (47 loc) · 1.5 KB
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
44
45
46
47
48
49
50
51
52
"""
Learn more about strings
"""
def main():
"""
Test function
:return:
"""
s1 = "This is super cool"
print("Size of s1", len(s1))
# Concatenation "+"
s2 = "Weber" + "State" + "University"
print(s2)
# If you need to join large strings, use the join() method
# Instead of + operator
teams = ["Real Madrid", "Barcelona", "Manchester United"]
record = ":".join(teams)
print(record)
# record = "\n".join(teams)
# print(record)
# Split record
print("Split rec", record.split(":"))
# Partitioning Strings
# You can use the "dummy" object: _
departure, _, arrival = "London:Edinburgh".partition(":")
print(departure, arrival)
t = "London:Edinburgh".partition(":")
print(t, type(t))
# String formatting using format()
print("The age of {0} is {1}".format("Mario", 34))
print("The age of {0} is {1}, and the birthday of {0} is {2}".format(
"Mario", 34, "August 12th"))
# Omitting the index
print('The best numbers are {} and {}'.format(4, 22))
# By field name
print("Current position {latitude} {longitude}".format(
latitude="60 N", longitude="5E" ))
# print elements of list
print("Galactic position x={pos[0]}, y={pos[1]}, z={pos[2]}".format(
pos=(85.6, 23.3, 99.0) ))
# Second version of "format": print(f"{var}") python 3.7 or greater
# fname = "Waldo"
# lname = "Weber"
# print(f"The WSU mascot is {fname} {lname}")
if __name__ == '__main__':
main()
exit(0)