Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I put the input inside a string which already exist?

I have a string called data, you can see below. I just want to take an input from user and put the input inside ability_id field in data.

def main():
    ability_id = input("Enter an ability id) # example:abc-123-abc-123
    data = '{"paw":"1234","ability_id": f"{ability_id}" ,"obfuscator":"plain-text"}'
    print(data)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

While I don’t think, saving the string like this has a lot of sense, I will still give you an answer to your question.
If you want to do it like this you can, as you already nearly did, use the f-string.
But you can’t just simply start an f-string inside a normal string – this is not, how this works. Instead, you have to make the whole thing an f-string and then indicate inside this string, where you want to place the variable. Something like this:

data = f'{{"paw":"1234","ability_id": "{ability_id}" ,"obfuscator":"plain-text"}}'

Attention: Watch out, that you use the double curly-brackets at the beginning and ending of the string, otherwise it will not work

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading