How to Convert String to Integer in Python

In Python, you can use the built-in int() function to convert a string to an integer. In this tutorial, I’ll show you an examples how to convert String to Integer in Python. Now let’s see an examples to do it.

UsingĀ  int() function

strVal="12"
print("Variable Type Before conversion : ", type(strVal))
intVal = int(strVal)
print("Variable Type After conversion : ", type(strVal))

Output:

Variable Type Before conversion : <class 'str'>
Variable Type Before conversion : <class 'int'>

I have an another article How to Convert Integer to String in Python, from where you can learn about different methods of converting data from Integer to String.

In this tutorial, I tried to brief how to convert integer to string in Python . Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page https://www.facebook.com/LearningBigDataAnalytics and stay connected.

Add a Comment