how typecast string to int in python?

how to read a string value as an integer in python? for eg if a=['1','2'] where 1 and 2 are characters. but these values are needed as integers for further operations like finding prime numbers between them

Your Answer


def primeNumber(a):
    for i in range(2, a):
        if ((a % i) == 0):
            print(a, "is not a prime number")
            break
    else:
        print(a, "is a prime number")

str=['1','2','4']
for i in range(len(str)):
    primeNumber(int(str[i]))

 I hope this program will help You.
 You should use this technique like
  a=int('1')

Python

Didn't get the answer.
Contact people of Talent-Python directly by clicking here