To create a file name dynamically using a string variable and concatenation, you can use f-string. Here's an example:
main.py91 chars3 lines
Alternatively, you can also use .format()
method to pass variable values into a string:
main.py99 chars3 lines
Both methods will result in the same file path:
main.py55 chars2 lines
Note that since the backslash is a special character in Python strings, you need to escape it with another backslash. This is why there are two backslashes in the file path.
gistlibby LogSnag