简体   繁体   English

用于 Mac 的 vs 代码上的基本任务的语法错误

[英]Syntax error for basic task on vs code for Mac

输入图片描述

Trying to run basic code in python but coming across this currently.尝试在 python 中运行基本代码,但目前遇到了这个问题。 It might have something to do with the path at which python is located.它可能与 python 所在的路径有关。 I have added the path where python is to the settings in vs code but may have done it incorrectly.我已将 python 所在的路径添加到 vs 代码中的设置,但可能做得不正确。

The error is in line 7: greeting - 'hello, {}'.format(who_to_greet) .错误在第 7 行: greeting - 'hello, {}'.format(who_to_greet)

You have subtracted the string 'hello, {}'.format(who_to_greet) from greeting instead of assigning it.您已从greeting中减去字符串'hello, {}'.format(who_to_greet)而不是分配它。

Change it to greeting = 'hello, {}'.format(who_to_greet) and you should be fine.将其更改为greeting = 'hello, {}'.format(who_to_greet)就可以了。

Your greet function is not defined on python terminal.您的问候 function 未在 python 终端上定义。 You can execute the function from terminal and use that function or You have to exit the python terminal and run the file from the directory.您可以从终端执行 function 并使用该 function 或者您必须退出 python 终端并从目录运行文件。 Use below code to exit the python shell.使用以下代码退出 python shell。

>>>exit()

After exiting.退出后。 Run your python file from the terminal like below.从终端运行 python 文件,如下所示。

>python hello.py

NB You can't run function in the terminal which is in your python script.注意您不能在 python 脚本中的终端中运行 function 。 To use a function in terminal, you have to execute that function from terminal also.要在终端中使用 function,您还必须从终端执行 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM