directory

  • Int function introduction
  • The int function is used
  • Guess you like it

Recommended path for learning Python: Python Learning Directory >> Python Basics

Int function introduction

Int is actually a variable type in Python that represents an integer, but it can also be used as a function. It is also a built-in function in Python that casts other numeric types to an integer. The syntax is as follows:

Parameter x: can be an integer, a floating-point number, or even a string STR type, such as 0,5,6.3, -78, "-10", "15"... Return value: Returns an integer number. <strong> If the argument is a floating point number, the decimal after the floating point number is removed by default. ''' int(x)Copy the code

Note: If the argument isString STRThe string cannot contain any character other than a number, for example, “10. A”.

The int function is used

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python int function. py @time :2021/04/04 11:00 @Motto: A thousand miles without a single step, a small stream without a river or sea, the wonderful life of the program needs unremitting accumulation! "" "print (" {} after int () function is used to calculate the result is {} ". The format (5, int (5))) print (" {} after int () function is used to calculate the result is {} ". The format (20, int (20))) # if the parameter is a floating point number, Format (5.3,int(5.3)) print("{} : {}". Format (5.3,int(5.3)) print("{} : {}". Format (-5.3,int(-5.3))) Print (" {} after the int () function is used to calculate the result is {} ". The format (" 12 ", int (" 12 "))) # print (" {} after int () function is used to calculate the result is {} ". The format (12 a, int (" 12 a "))) / / valueError Output: 5 evaluates to 5-20 evaluates to -20 5.3 evaluates to -5 12 evaluates to 12 ""Copy the code

3.Guess you like

  1. Python string/list/tuple/dictionary conversions
  2. Python local and global variables
  3. The Python type function is different from the isinstance function
  4. Python is differs from ==
  5. Python mutable and immutable data types
  6. Shallow and deep copies of Python
  7. Python recursive functions
  8. Python sys module
  9. The Python list
  10. The Python tuple tuple
  11. Python dictionary dict
  12. Python conditional derivations
  13. Python list derivations
  14. Python dictionary derivations
  15. Python function declarations and calls
  16. Python variable argument *argc/**kargcs

Python int function

This article is published by the blog – Ape Say Programming Ape Say programming!