python--Data type Conversions

Source: Internet
Author: User

Python implements data type conversions with built-in functions

Grammar Example Describe
Int () Int (1.0), int (' 1 ')

Can be converted to include string types and other numeric types, but will lose precision

Float () Float (1), float (' 1 ')

You can convert string and other numeric types, and the insufficient number of digits is 0, for example 1 becomes 1.0

STR () STR (1)

Convert to String

Complex (real, imag)

Plural

Repr Repr (Object)

Returns the string format of an object

Eval ()

Eval ("12+23") Executes a string expression that returns the result of the calculation, as shown in the example 35

Tuple ()

Convert to tuple

List ()

Convert to List

Set ()

Convert to a collection, while going back to the

Frozenset ()

Frozenset ([0, 1, 2, 3]) Transforms an iterative object into an immutable collection

Chr ()

Ord ()

Ord (' a ') Returns the corresponding ASCII value

Hex ()

Hex (12) Convert an integer to a hexadecimal string

Oct ()

Oct (12) Convert an integer to an octal string

python--Data type Conversions

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.