List Items - Cleaning Up the List pt2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

18th Jan 2020, 1:17 PM
Anthony B.
Anthony B. - avatar
4 Answers
+ 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?
18th Jan 2020, 1:36 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
Thanks folks!
18th Jan 2020, 1:45 PM
Anthony B.
Anthony B. - avatar
0
print(f"Hey, the whole gang is here {guest_list[2].title()}. You coming to eat?")
18th Jan 2020, 1:39 PM
rodwynnejones
rodwynnejones - avatar
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
18th Jan 2020, 1:39 PM
HNNX 🐿
HNNX 🐿 - avatar