Record#
- Today I learned about string manipulation.
- 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() = removes leading and trailing whitespace.
- When manipulating strings, it is important to pay attention to the order of functions. For example, in the string = ' phone'.capitalize().strip(), the result after execution is 'phone', not 'Phone'. This is because capitalize() capitalizes the letter after removing whitespace.
- 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")