Hi,
I was wondering if there is a simple way to split 1234 into a string of ('1', '2', '3', '4').
Also, is there a way to test whether an element of a string (or list) is an integer. For instance, if i had a list a = ['1', '2', '3', '4'], the elements are all integers, the function needs to return True.
However, if the list was ['1', '2', '3', 'x'], how would i distinguish that 'x' is not an integer and therefore the function would return False.
So far i have used a for loop:
for i in a:
if int(i) is type(int):
return True
if int(i) is not type(int):
return False
but this isn't working at all.
Thanks for your help :)
I was wondering if there is a simple way to split 1234 into a string of ('1', '2', '3', '4').
Also, is there a way to test whether an element of a string (or list) is an integer. For instance, if i had a list a = ['1', '2', '3', '4'], the elements are all integers, the function needs to return True.
However, if the list was ['1', '2', '3', 'x'], how would i distinguish that 'x' is not an integer and therefore the function would return False.
So far i have used a for loop:
for i in a:
if int(i) is type(int):
return True
if int(i) is not type(int):
return False
but this isn't working at all.
Thanks for your help :)
Comment