0
List Items - Cleaning Up the List pt2
I am trying to create unique messages for each guest. The output for the last guest has the dreaded apostrophes around the name. How do I remove the apostrophes around the name Luke? Code below: guest_list = ['John', 'Mark', 'Luke'] print(f"{guest_list[0].title()}, my wife is making meatloaf. Would you like some?") print(f"{guest_list[1].title()}, John is coming to dinner later. You down?") print(f"Hey, the whole gang is here 'f{guest_list[2].title()}'. You coming to eat?") Output: John, my wife is making meatloaf. Would you like some? Mark, John is coming to dinner later. You down? Hey, the whole gang is here 'Luke'. You coming to eat?
4 Respostas
+ 1
Just delete them because you put those there.
guest_list = ['John', 'Mark', 'Luke']
print(f"{guest_list[0].title()}, my wife is making meatloaf. Would you like some?")
print(f"{guest_list[1].title()}, John is coming to dinner later. You down?")
print(f"Hey, the whole gang is here {guest_list[2].title()}. You coming to eat?")
See the difference?
+ 1
Thanks folks!
0
print(f"Hey, the whole gang is here {guest_list[2].title()}. You coming to eat?")
0
You nerd an escape character.
If you want the compiler to "ignore" a command and treat something as a string literal, you'll have to use backlash + character like so :
\" will print "
\\ will print \
\' will print '
There's more for tabs, paragraphs and whitespace - look up python escape characters