二手产品经理

二手产品经理

THIS IS RENO

String Processing - 37 Days - Learn Python Online in 100 Days

  1. Today's study is about string operations.
  2. Strings come with default indexing, for example, txt="hello hello". print(txt[0]) will print h.
  3. 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.
  4. 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.
  5. split() processes the string into an array through function parameters.
  6. 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]}")
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.