What is the role of f in Python?

Asked 2 years ago, Updated 2 years ago, 14 views

for i in range(1, 100):
    print (f'{i}01')

It only works if there is f here, so what is the role of f?

python

2022-09-20 18:59

1 Answers

There are several ways to format strings in Python. One of them is called f-string. A string with f is replaced by converting the value of the variable into a string by inserting a variable in an interval separated by {}.

For more information, the official document See https://docs.python.org/ko/3/tutorial/inputoutput.html#formatted-string-literals and other descriptions.


2022-09-20 18:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.