Python int() FunctionPython int() function is used to get the integer value. It returns an expression converted into an integer number. If the argument is a floating point, the conversion truncates the number. If the argument is outside the integer range, It converts the number into long type. If the number is not a number or if a base is given, the number must be a string. SignatureParametersx : A number which is to be converted into integer type. base: It is an Optional argument if used number must be a string. ReturnIt returns an integer value. Let's see some examples of int() function to understand it's functionality. Python int() Function Example 1It is a simple python example which converts float and string values into an integer type. The float value is truncated by the function and returned an integer instead. Output: integer values : 10 10 10 Python int() Function Example 2To verify the type of returned value, we can use type function. The type function returns the type of value. See an example below. Output: <class 'int'> <class 'float'> <class 'str'> values after conversion 10 10 10 and types are: <class 'int'> <class 'int'> <class 'int'> Python int() Function Example 3Output: Values after conversion: 2 175 8 and types are: <class 'int'> <class 'int'> <class 'int'> Next TopicPython Functions |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India