3 ms·
What is the f doing in url = f"https://api.ourservice.com/media?page{page}&step=100 https://api.ourservice.com/media?page{page}&step=100 ?
by dncornholio 4y ago
What is the f doing in
url = f"https://api.ourservice.com/media?page{page}&step=100 https://api.ourservice.com/media?page{page}&step=100 ?
- fifticon 4y agoif it's python, it's the formatting/interpolation string marker.
- jraph 4y agof for format ("formatted string"). It does the same thing as `https://api.ourservice.com/media?page${page}&step=100 https://api.ourservice.com/media?page${page}&step=100` [sic] in Javascript, or "https://api.ourservice.com/media?page$page&step=100 https://api.ourservice.com/media?page$page&step=100" in Bash, PHP, Perl or Groovy (and other languages). It outs you into variable substitution / interpolation in the string literal. In Python these string literals are called f-strings if you want to look it up. They are defined in PEP 498 - Literal String Interpolation [1] and available since Python 3.6. [1] https://peps.python.org/pep-0498/ https://peps.python.org/pep-0498/ [sic] there probably would be a missing '=' in this url after "?page"
- qwertox 4y ago"f-strings", a (new) way to format strings.
- throwaway744678 4y agoIt's a Python f-string [0]. A way of formatting a string by directly including a Python expression between curly braces. [0] https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings https://docs.python.org/3/tutorial/inputoutput.html#tut-f-st...