Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between "f" and "F" in Python string formatting?

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?

like image 331
S.S. Avatar asked Dec 31 '25 20:12

S.S.


1 Answers

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.

like image 79
Blusky Avatar answered Jan 03 '26 08:01

Blusky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!