Answers for "python check if variable is array or string"

13

if type is string python

isinstance(s, str)
Posted by: Guest on March-22-2020
3

python check if string

type('hello world') == str
# output: True

type(10) == str
# output: False
Posted by: Guest on April-06-2020
0

python check string or number array

numbers = []
animals = []
with open('textfile.txt') as f:
    for x in f:
        try:
            numbers.append(int(x.replace("n", "")))
        except:
            animals.append(str(x.replace("n", "")))
print(numbers)
print(animals)

# Output
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# ['dog', 'cat', 'fish', 'bird']
Posted by: Guest on May-22-2021

Code answers related to "python check if variable is array or string"

Python Answers by Framework

Browse Popular Code Answers by Language