Reputation: 758
To format strings in Python 3.6+, I usually use the lowercase "f" option to include variables. For example:
response = requests.get(f'{base_url}/{endpoint}?fields={field_list}')
I've recently seen one of my coworkers who always uses capital "F", instead. Like this:
response = requests.get(F'{base_url}/{endpoint}?fields={field_list}')
Is there a difference between the lowercase "f" and capital "F"? And if yes, when would you use each?
Upvotes: 13
Views: 3974
Reputation: 1
There is no difference between the two. For better understanding, you may go through string formatting.
Upvotes: 0
Reputation: 531718
There is no difference at all. See the definition of Formatted string literals in the Python documentation.
A formatted string literal or f-string is a string literal that is prefixed with 'f' or 'F'.
No further mention is made of the specific character used to introduce the literal.
Upvotes: 3
Reputation: 3784
As explained in the PEP 498, chapter Specification, both are accepted, and should not differ.
In source code, f-strings are string literals that are prefixed by the letter 'f' or 'F'. Everywhere this PEP uses 'f', 'F' may also be used.
Upvotes: 13