使用or语句返回函数 [英] Returning on a function with an or statement

查看:108
本文介绍了使用or语句返回函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def obtain_type_player(self):
    '''
    This method will be used by the sub-classes PlayerHuman and PlayerComputer.

    Returns:
        Le type de player, 'Computer' or 'Human'
    '''



    return 'Human' or 'Computer'







我想知道这是否会归还对我来说或者我必须添加一些代码。



我尝试过:



这是使用Python OOP,因为它链接到很多其他方法,我很困惑,但我只是在这里,以确保这是返回它的方式,因为我很难在我的代码中测试在某种程度上。




I was wondering if this would return the rght thing for me or if i had to add some code.

What I have tried:

This is using Python OOP and since its linked to a lot of other method, im confused but im just here to make sure that this is the way to return it because its hard for me to test in my code in a way.

推荐答案

如何决定返回哪个值?您需要添加决策声明( if )以选择正确的答案。类似于:

How can it decide which value to return? You need to add a decision statement (if) to select the correct answer. Something like:
def obtain_type_player(self):
    type = "Computer" # the default answer
    if some_other_information is true:
        type = "Human"
    return type


这篇关于使用or语句返回函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆