-1

I'm new to python and learning strings formatting. I'm formatting this string using f-strings, I do this using %s but I want to do this with f-strings.

query = f'''
            summary {
                operation(
                    input: {
                        operation_type: accounts,
                        user_id: {user_id},
                        user_secret: {user_secret},
                        code: {user_id}
                    }
                ) {
                    user_accounts,
                    user_account_type
                }
            }'''
M Usman Wahab
  • 53
  • 1
  • 10

1 Answers1

2

Since {} are used to escape variable names, you need to double them to represent actual curly braces:

query = f'''
            summary {{
                operation(
                    input: {{
                        operation_type: accounts,
                        user_id: {user_id},
                        user_secret: {user_secret},
                        code: {user_id}
                    }}
                ) {{
                    user_accounts,
                    user_account_type
                }}
            }}'''
Lukas Schmid
  • 1,895
  • 1
  • 6
  • 18