元组做函数的参数

2023年1月21日13:29:52

用元组做参数,可以减数重复的逻辑代码

# -*- coding:utf8 -*-

demo = u"你喜欢吃饭吗"
# demo = u"你喜欢吃饭吗?"
if demo.endswith((u"吗", u"?")):
    print("test")
    
# 等价写法
if demo.endswith(u"吗") or demo.endswith(u"?"):
    print("test")

  • 作者:是晨星啊
  • 原文链接:https://blog.csdn.net/s1162276945/article/details/104430801
    更新时间:2023年1月21日13:29:52 ,共 169 字。