• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
June 17, 2022 |69.8K Views

Python Program to Convert String to an Integer

Description
Discussion

In this video, we will learn how to convert a String to an Integer using python. We have divided this video into 5 sections.

Below is the list that we will cover in this section:

1. A brief explanation to convert a String to an Integer using python.
2. Convert String to an Integer using the build-in int() function
3. Convert String to an Integer using the build-in float() function
4. Convert String to an Integer using the built-in eval() function
5. Convert String to an Integer using ASCII ord() function.

The built-in int() method in Python can be used to convert strings to integers. Any python data type can be passed to the int() method, which converts it to an integer.

Conversion can also be done using the float() keyword, here we will first convert to float, then we will convert float into an integer.
The eval() method in Python parses the expression parameter and evaluates it as a python expression, then executes the python expression.

Another method is to use ASCII. In this, we will use the ord() method in Python to return a character's Unicode code. 
This function takes a unit-length string as an argument and returns the Unicode equivalent of that string.

Python Program to Convert String to an Integer :
https://www.geeksforgeeks.org/convert-string-to-integer-in-python/