Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.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_Python 3.x_Visual Studio Code - Fatal编程技术网

Python方法不会出现在用户定义的函数中

Python方法不会出现在用户定义的函数中,python,python-3.x,visual-studio-code,Python,Python 3.x,Visual Studio Code,创建用户定义的函数时,内置方法不会作为选项弹出 在文件的主体中,这些方法不会出现问题。只有当你创建一个函数时,它们才不会出现 def strip\u标点符号(astring): #标点符号字符=[“”、“”、“、”、“、”、“!”、“:”、“;”、“#”、“@”] astring.replace() 返回(收敛) #主文件 my_string=“Word的!" my_string.replace() 在VS代码中,无论是在用户定义函数中,还是在函数外部,我都希望有相同的行为。如果您使用类型注

创建用户定义的函数时,内置方法不会作为选项弹出

在文件的主体中,这些方法不会出现问题。只有当你创建一个函数时,它们才不会出现

def strip\u标点符号(astring):
#标点符号字符=[“”、“”、“、”、“、”、“!”、“:”、“;”、“#”、“@”]
astring.replace()
返回(收敛)
#主文件
my_string=“Word的!"
my_string.replace()

在VS代码中,无论是在用户定义函数中,还是在函数外部,我都希望有相同的行为。

如果您使用类型注释重写代码,您应该得到您想要的:

def strip\u标点符号(astring:str)->str:
astring.replace()
回程收敛

因为您的文本编辑器无法知道
astring
应该是
str
对象。Python是一种动态类型的语言,没有什么可以阻止您将任何对象传递给
strip\u标点符号
,那么您希望它如何知道它应该建议字符串方法,而不是说list methodods?在
my_string=“Words”的情况下!“”可以,因为您直接分配了<代码> STR 文字。您应该考虑使用类型注释。