Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python格式化字符串无效语法_Python_String_String Formatting - Fatal编程技术网

Python格式化字符串无效语法

Python格式化字符串无效语法,python,string,string-formatting,Python,String,String Formatting,在Python3.7中,我有一个非常简单的脚本。为什么会抛出无效的语法错误 datestr = '2020-06-10' print(f"C:/folder/{datestr.replace("-", "_")}/temp.csv") File "<ipython-input-38-95d22e47df04>", line 2 print(f"C:/folder/{datestr.replace("-", "_")}/temp.csv")

在Python3.7中,我有一个非常简单的脚本。为什么会抛出无效的语法错误

datestr = '2020-06-10'
print(f"C:/folder/{datestr.replace("-", "_")}/temp.csv")


 File "<ipython-input-38-95d22e47df04>", line 2
    print(f"C:/folder/{datestr.replace("-", "_")}/temp.csv")
                                             ^
SyntaxError: invalid syntax
您试图在同一字符串中用于不同目的。 您可以将其与“”交换,以停止字符串操作和终止字符串之间的任何混淆:

datestr = '2020-06-10'
print(f"C:/folder/{datestr.replace('-', '_')}/temp.csv")

希望这有帮助

您试图在同一字符串中用于不同目的。 您可以将其与“”交换,以停止字符串操作和终止字符串之间的任何混淆:

datestr = '2020-06-10'
print(f"C:/folder/{datestr.replace('-', '_')}/temp.csv")


希望这有帮助

printC://folder//+strdatestr.replace-,+///temp.csv为什么代码在字符串中???您的代码不能在字符串中工作。@它是一个高辛烷值,因此一旦字符串分隔符的问题得到解决,这将起作用。printC://folder//+strdatestr.replace-,\uu+//temp.csv为什么您的代码在字符串中???您的代码在字符串中不起作用。@它是一个高辛烷值,所以一旦字符串定界符的问题得到解决,这将起作用。