二手产品经理

二手产品经理

THIS IS RENO

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

Records#

  1. Today's study is about handling strings.
    1. string.lower() = converts all letters to lowercase
    2. string.upper() = converts all letters to uppercase
    3. string.title() = capitalizes the first letter of each word
    4. string.capitalize() = capitalizes the first letter of the first word
    5. string.strip() = ignores spaces
  2. When handling strings, pay attention to the order of functions. For example, for the string = ' phone'.capitalize().strip(), the result after execution is phone, not Phone. This is because capitalize() capitalizes the letters after removing spaces.
  3. Today's exercise: Create an address book program that does not allow duplicates.
namelist = []
while True:
  firstname = input("First Name: ").title()
  lastname = input("Last Name: ").title()
  myname = f"{firstname} {lastname}"
  if myname not in namelist:
    namelist.append(myname)
    print(myname)
  else:
    print("ERROR: Duplicate name")
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.