how can I check in a statement if a variable is an integer?
like for string, we can say:
if i == " "
return something
how would I say: if i == integer
??
how can I check in a statement if a variable is an integer?
like for string, we can say:
if i == " "
return something
how would I say: if i == integer
??
Like this:
if type(i) == int:
do_this()
Or like this:
if isinstance(i, int):
do_this()
You will find more info here: What's the canonical way to check for type in Python? (of which I think your question is a duplicate)
Using isinstance
:
for kee, val in valStore.items():
if isinstance(key, int):
writehist.writerow([key] + [val])