The equivalents of abc.Sequence in Python 2 I need to convert to some Python 3 code to Python 2 code from collections.abc import Sequence def to_tensor(X, device): ..... if isinstance(X, (list, tuple)): return [to_tensor_(x) for x in X] if isinstance(X,Sequence):<-------equals to if isinstance(X,(str,bytes))? X = torch.tensor(np.array(X)) return X.to(device) as you can see above, I want to know whether: isinstance(X,Sequence) equals to isinstance(X,(str,bytes)) and the documentation does not make any sense to me. 1 Answer 1 Short answer: no, it's not equivalent. Longest answer: First, Python2 has no "bytes" type - Python3 bytes are Python2 str and Python3 str is Python2 unicode , so the right question would be: is isinstance(X,Sequence) equivalent to isinstance(X, (unicode, str)) . bytes str str unicode isinstance(X,Sequence) isinstance(X, (unicode,...