0

How can I make this print the value instead of just the string??

So I’m trying to make a group of characters from a board game and make their data display based on user input. print("Name: {self.name}") There’s the print statement, my problem is it returns exactly what’s in the quotes, but if I move the quotes to not encompass {self.name} it results in a syntax error. I’ve included the rest of my code if it helps, but I’m stumped. https://sololearn.com/compiler-playground/csavx9wjLpLA/?ref=app

13th Feb 2025, 5:44 PM
Squilliam Fancyson
4 odpowiedzi
+ 5
f-string is missing
13th Feb 2025, 5:51 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 3
Squilliam Fancyson As Mihaly pointed out, you are missing the f right before the first string quote which lets Python know it is a formatted string instead of a normal string. Correct usage - print(f"Name: {self.name}")
13th Feb 2025, 10:01 PM
Shardis Wolfe
+ 2
Squilliam Fancyson variable names are not just simple strings. you can't access variable names and call class methods simply through user input. at least not safely or without hacky eval codes. maybe do something like this instead: https://sololearn.com/compiler-playground/cGU8R7HI4hC1/?ref=app
14th Feb 2025, 3:07 AM
Bob_Li
Bob_Li - avatar
0
Put "f" before the first "
15th Feb 2025, 9:38 AM
✰ 𝙱𝙻𝙰𝙲𝙺 𝙹𝙰𝙲𝙺 么 ✰
✰ 𝙱𝙻𝙰𝙲𝙺 𝙹𝙰𝙲𝙺 么 ✰ - avatar