In [1]:
import numpy as np
In [2]:
l = [0, 1, 2]
print(type(l))
In [3]:
print(hasattr(l, 'append'))
In [4]:
print(hasattr(l, 'xxx'))
In [5]:
print(len(l))
In [6]:
print(l.__len__())
In [7]:
def print_len_hasattr(x):
if hasattr(x, '__len__'):
print(len(x))
else:
print('x has no __len__')
In [8]:
print_len_hasattr([0, 1, 2])
In [9]:
print_len_hasattr('abc')
In [10]:
print_len_hasattr(100)
In [11]:
a = np.arange(3)
print(a)
In [12]:
print_len_hasattr(a)