Analysis of int () function usage in Python, pythonint

Source: Internet
Author: User

Analysis of int () function usage in Python, pythonint

Int () is an internal function of Python.

This is what we say in the Python help.

>>> help(int) Help on class int in module __builtin__: class int(object)  | int(x[, base]) -> integer  |   | Convert a string or number to an integer, if possible. A floating point  | argument will be truncated towards zero (this does not include a string  | representation of a floating point number!) When converting a string, use  | the optional base. It is an error to supply a base when converting a  | non-string. If base is zero, the proper base is guessed based on the  | string content. If the argument is outside the integer range a  | long object will be returned instead. >>> int(12.0) 12 

The int () function can convert a number into an integer.

>>> int('12',16) 18  

There are two points to note: 1) 12 the input must be in the form of a string, if the base parameter is included

2) here 12 is not converted to a hexadecimal number, but 12 is a hexadecimal number. The int () function is expressed in decimal number, as shown below:

>>> int('0xa',16) 10 >>> int('10',8) 8 

Summary

The above section describes how to use the int () function in Python. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.