How is String slice useful?
6/1/2019 1:45:58 PM
Da Talking Pigeon
2 Answers
New AnswerIt actually has many uses. For example: when asking for uset conformation, you can make it so that they can enter both "Y" and "yes" i = input("You like Python? Y / N\n") if i[0].lower() == 'y': print("I thought so") else: print( ":(" ) Another example is grouping related variables. Say you have a big dictionary of names with cellphone numbers. You can choose to only display people starting with a given substring namedict = {"Thomas": 1027, "Abigail": 2080 "Gavin": 3466} name = input("Name") print(*[(n + '\n') for n in namedict if n.startswith(name)]) The examples given might not be optimised or functional, but I hope you get the message