简体   繁体   English

样式:返回一个元组

[英]Style: a tuple is returned

I have come across such a coding style for cases when a tuple is returned. 对于元组返回的情况,我遇到过这种编码样式。

_, number_of_days_in_month = calendar.monthrange(year, month)

In this case monthrange returns a tuple with two values: weekday of first day of the month and number of days in month. 在这种情况下, monthrange返回具有两个值的元组:每月第一天的工作日和每月的天数。

  1. Is this style acceptable? 这种风格可以接受吗? Is it described in some famous style guides like Google Python Style Guide? 是否在某些著名的样式指南(例如Google Python样式指南)中进行了描述?

  2. What should I do if _ is already occupied? _已被占用怎么办? For example, in Django it is used for translation like this: 例如,在Django中,它用于这样的翻译:

     from django.utils.translation import ugettext as _ output = _("Welcome to my site.") 

I think, we sould follow the advice from The Hitchhiker's Guide to Python: 我认为,我们应该遵循《 The Hitchhiker's Python指南》的建议:

http://python-guide-pt-br.readthedocs.io/en/latest/writing/style/#create-an-ignored-variable http://python-guide-pt-br.readthedocs.io/en/latest/writing/style/#create-an-ignored-variable

That is: use __ in this case. 也就是说:在这种情况下,请使用__。

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

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