def is_two(x): """ 判断一个变量是否等于数字2或字符串“2” """ return x == 2 or x == '2'
示例:
print(is_two(2)) # True print(is_two('2')) # True print(is_two(3)) # False print(is_two('hello')) # False
上一篇:编写一个函数longest_word,要求用户输入一些单词,并返回用户输入的最长单词
下一篇:编写一个函数模拟掷骰子过程。