Python 参数里面的冒号是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41648300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:21:11  来源:igfitidea点击:

What does the colon inside the parameter mean?

python

提问by rap sea

What does the colon on words_pron_dict:str mean? I am getting syntax error on python 2.7. Is it python 3? How can i use it?

words_pron_dict:str 上的冒号是什么意思?我在 python 2.7 上遇到语法错误。是蟒蛇3吗?我怎样才能使用它?

class TextToSpeech:
    CHUNK = 1024

    def __init__(self, words_pron_dict:str = 'cmudict-0.7b.txt'):
        self._l = {}
        self._load_words(words_pron_dict)

回答by Lucero

It's a type annotation: https://docs.python.org/3/library/typing.html

这是一个类型注释:https: //docs.python.org/3/library/typing.html

You should be able to just remove it.

您应该能够将其删除。