What does "f" character in front of the string mean?

Quantum_07 report abuse

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?


Lu-at-Imaginghub report abuse

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

Quantum_07 report abuse

Can multiline string be f-strings?

sasha_sasha report abuse

Yes, syntax is the same:

select {columns}
from {table}
where 'timestamp' <= {timestamp};

Notice, it is possible to use braces inside f-strings.

Add Answer

Need support?

Just drop us an email to ... Show more