繁体   English   中英

我怎样才能简化这个?

[英]How I can simplify this?

我想简化这些“如果”,有哪些变体? 谢谢。

    user_id = message.from_user.id
    user = user_data[user_id]
    user.profil = message.text
    if not user.profil == '97':
        if not user.profil == '82':
            if not user.profil == '72':
                if not user.profil == '64':
                    if not user.profil == '45':
                        if not user.profil == '25':   
                            markup = types.ReplyKeyboardMarkup(one_time_keyboard=True)
                            markup.add('97', '82', '72', '64', '45', '25')
                            msg = bot.send_message(message.chat.id, 'אנא בחר פרופיל.', reply_markup=markup)
                            bot.register_next_step_handler(msg, process_profil_step)
                            return

not in你可以这样做:

unwanteds = {'97', '82', '72', '64', '45', '25'}
if user.profil not in unwanteds:
    markup = ...

所以这会检查 user.profil 是否不在不需要的集合中。 {} 进行设置,因此查找速度有点快。

暂无
暂无

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

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