Combine f-string and raw string literal

You can combine the f for an f-string with the r for a raw string:

user="Alex"
dirToSee = fr'C:\Users\{user}\Downloads'
print (dirToSee) # prints C:\Users\Alex\Downloads

The r only disables backslash escape sequence processing, not f-string processing.

Quoting the docs:

The ‘f’ may be combined with ‘r’, but not with ‘b’ or ‘u’, therefore raw formatted strings are possible, but formatted bytes literals are not.

Unless an ‘r’ or ‘R’ prefix is present, escape sequences in string and bytes literals are interpreted…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)