Try using triple curly braces. {{ gets converted to a string { (It is an escape sequence).
AccessToken = "AccessTokenValue"
payload={}
headers = { 'authorization': f'{{{AccessToken}}}'}
print(headers)
This will print: {'authorization': '{AccessTokenValue}'}
python - Can you insert anything other than a variable in {curly braces} of an f string literal? - Stack Overflow
Curly bracket in this code (beginner)
Python F string, insert string with curly brackets inside curly bracket - Stack Overflow
python - How do I escape curly-brace ({}) characters characters in a string while using .format? - Stack Overflow
Videos
I'm confused about the use of the curly brackets in this code from a textbook. I thought the curly brackets are to call dictionaries. but first and last are not, am I right?
def get_formatted_name(first,last):
full_name=f"{first}{last}"
return full_name.title()
You need to double the {{ and }}:
>>> x = " {{ Hello }} {0} "
>>> print(x.format(42))
' { Hello } 42 '
Here's the relevant part of the Python documentation for format string syntax:
Format strings contain “replacement fields” surrounded by curly braces
{}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling:{{and}}.
Python 3.6+ (2017)
In the recent versions of Python one would use f-strings (see also PEP498).
With f-strings one should use double {{ or }}
n = 42
print(f" {{Hello}} {n} ")
produces the desired
{Hello} 42
If you need to resolve an expression in the brackets instead of using literal text you'll need three sets of brackets:
hello = "HELLO"
print(f"{{{hello.lower()}}}")
produces
{hello}