jupyter notebook for python (七)
(1)
String formatting methods
the following methods are applied to string objects
- .capitalize() - capitalizes the first character of a string
- .lower() - all characters of a string are made lowercase
- .upper() - all characters of a string are made uppercase
- .swapcase() - all characters of a string are made to switch case upper becomes lower and vice versa
-
.title() - each 'word' separated by a space is capitalized
(2)
Formatting string input()
When storing input, sometimes a specific format is needed and formatting is applied to the input()
function
Note: this technique overwrites the original user input in the variable with the formatted value
(3)program(task)
What is on the menu
[ ] Create a program where a user can check if an item is on the menu
- store the user response in a variable menu_ask
- use the menu from above and add some additional items
- the program should be able to ignore case mismatch so that "hello" is found in "Hello World!"
[ ] Challenge: Add to the menu
- print the current menu
- get user input for add_item variable
- new_menu use string addition to add add_item to menu
- print the new_menu testing
- add a cell below add menu
- check if an item is on the menu, check for previous items and the item you added