What does "f" character in front of the string mean?
I noticed that sometimes strings in python have an "f" symbol in front of them. Also, they have some values in "{}".
For example: f'directory/{filename}'.
So what are those strings?
I noticed that sometimes strings in python have an "f" symbol in front of them. Also, they have some values in "{}".
For example: f'directory/{filename}'.
So what are those strings?
Hello @Quantum_07
They are known as "f-string" and used to format strings in python. They were added in 3.6 and the syntax is:
f'some text {var1} more text {var2}', where 'var1' and 'var2' are previously defined variables.
As you can see the syntax is very compact and user-friendly.
Best regards, Lu
Can multiline string be f-strings?
Yes, syntax is the same:
f"""
select {columns}
from {table}
where 'timestamp' <= {timestamp};
"""
Notice, it is possible to use braces inside f-strings.
Just drop us an email to ... Show more