Records#
- Today's study is about handling strings.
- string.lower() = converts all letters to lowercase
- string.upper() = converts all letters to uppercase
- string.title() = capitalizes the first letter of each word
- string.capitalize() = capitalizes the first letter of the first word
- string.strip() = ignores spaces
- 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.
- 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")