小编yas*_*eth的帖子

How to check a specific type of tuple or list?

Suppose,

var = ('x', 3)
Run Code Online (Sandbox Code Playgroud)

How to check if a variable is a tuple with only two elements, first being a type str and the other a type int in python? Can we do this using only one check? I want to avoid this -

if isinstance(var, tuple):
    if isinstance (var[0], str) and (var[1], int):
         return True
return False
Run Code Online (Sandbox Code Playgroud)

python types tuples isinstance

5
推荐指数
2
解决办法
3918
查看次数

标签 统计

isinstance ×1

python ×1

tuples ×1

types ×1