- Today's study is about string operations.
- Strings come with default indexing, for example, txt="hello hello". print(txt[0]) will print h.
- Index values are determined by colons to specify a range, for example, print(txt[1:10]) will print characters from 1 to 9. The actual printed range does not include 10.
- Besides specifying a range, you can also specify a step. For example, print(txt[::2]) will print hlo... If it's print(txt[::-1]), it will reverse the string and print "olleh olleh". This parameter cannot be 0.
- split() processes the string into an array through function parameters.
- Today's exercise is to let the user input multiple strings and compose a new string from each of them.
print("STAR WARS NAME GENERATOR")
print()
t1 = input("enter your first name: ")
t2 = input("enter your last name: ")
t3 = input("enter your mum's maiden name: ")
t4 = input("enter the city where you were born: ")
print(f"Your Star wars name is {t1[0:4]}{t2[0:3]} {t3[0:3]}{t5[-3]}")