List Items - Cleaning Up the List pt2 | SoloLearn: Learn to code for FREE!

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?

1/18/2020 1:17:40 PM

Anthony B.

4 Answers

New Answer

+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