isinstance function python
x = isinstance(5, int)
y = isinstance(6.5, int)
print(x)
print(y)
output:
True
False
isinstance function python
x = isinstance(5, int)
y = isinstance(6.5, int)
print(x)
print(y)
output:
True
False
isinstance python
sample_list = ['Emma', 'Stevan', 12, 45.6, 1 + 2j, "Eric", ]
number_list = []
string_list = []
for item in sample_list:
if isinstance(item, (int, float, complex)):
number_list.append(item)
elif isinstance(item, str):
string_list.append(item)
# String List
print(string_list)
# Output ['Emma', 'Stevan', 'Eric']
# Number list
print(number_list)
# Output [12, 45.6, (1+2j)]
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us