PY
py
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
# It shows how we can manuplulate strings with python
# We learned how to concatenate strings with + from SoloLearn
print("What we learned from SoloLearn using '+' sign.")
print("This is the " + "USS Enterprise " + "of the " + "United Federation" + ".")
# How about we want to display a sentence many times but with different words?
print("This is the " + "ISS Enterprise " + "of the " + "Terran Empire" + ".")
print("This is the " + "IKS Bortas " + "of the " + "Klingon Empire" + ".")
print() # This use to seperate the output
# As you see, the sentence is almost the same with different shipname and owner.
# Now we put the names and owner into a variable
names = ['USS Enterprise', 'ISS Enterprise', 'IKS Bortas']
owner = ['United Federation', 'Terran Empire', 'Klingon Empire']
# string.format() method
# We can create a string and put {} inside where you want to change
print("Using string.format() method")
print("This is the {} of the {}.".format(names[0], owner[0]))
print("This is the {} of the {}.".format(names[1], owner[1]))
print("This is the {} of the {}.".format(names[2], owner[2]))
print()
# The order of the format() arguments need to be the same order as you want
print("Watch out the arguments order!")
print("This is the {} of the {}.".format(owner[1], names[1]))
print("Who?")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run