How to check datatype with isinstance() in Python

2 Answers

0 votes
n = 8
if isinstance(n, int):
    n += 1
elif isinstance(n, str):
    n = int(n)
    n += 3

print(n)


'''
run:

9

'''

 



answered Sep 21, 2017 by avibootz
0 votes
n = '8'
if isinstance(n, int):
    n += 1
elif isinstance(n, str):
    n = int(n)
    n += 3

print(n)


'''
run:

11

'''

 



answered Sep 21, 2017 by avibootz

Related questions

1 answer 90 views
2 answers 232 views
232 views asked Aug 30, 2016 by avibootz
1 answer 173 views
173 views asked Feb 26, 2016 by avibootz
...