0

Suppose I have a string object named greeting, and has content: 'Good {time}!'

Suppose I then have an another string object named time, and has content: 'morning'

I know if I now execute:

print(f'Good {time}!')

will print:

Good morning!

But how can I now make greeting has content: 'Good morning!'

zhonhel
  • 41
  • 3
  • Hint: look up the documentation for f-strings, and in particular, look at the description of what they replaced/upgraded from. – Karl Knechtel Dec 24 '21 at 07:50
  • I can't find the solution from the duplicate link, can anyone give a help? – zhonhel Dec 24 '21 at 07:57
  • See all the stuff in the duplicate link where it talks about the `.format` method? Do you understand, from the link, what that does? Do you see how you could use that to solve the problem? – Karl Knechtel Dec 24 '21 at 07:58
  • I still can't find solution... Can you simply tell me, how to concrete the `greeting` variable in my question, Thank you! – zhonhel Dec 24 '21 at 08:20
  • I think maybe I can try to use eval() – zhonhel Dec 24 '21 at 08:29
  • No. You can use the `.format` method, as described in the linked duplicate. There are examples of usage there. This is not a code-writing service. – Karl Knechtel Dec 24 '21 at 09:02
  • @Karl Knechtel Please see my question again, I know how to use `.format()` normally – zhonhel Dec 24 '21 at 09:46

0 Answers0