Conversion between Python data types and python Data Types

Source: Internet
Author: User

Conversion between Python data types and python Data Types

Conversion between Python Data Types

Function Description

Int (x [, base])

Converts x to an integer.

Long (x [, base])

Converts x to a long integer.

Float (x)

Convert x to a floating point number.

Complex (real [, imag])

Create a plural number

Str (x)

Convert object x to a string

Repr (x)

Convert object x to an expression string

Eval (str)

Used to calculate a valid Python expression in a string and return an object

Tuple (s)

Converts the sequence s into a single tuples.

List (s)

Converts sequence s to a list.

Set (s)

Convert to a variable set

Dict (d)

Create a dictionary. D must be a sequence (key, value) tuples.

Frozenset (s)

Convert to an unchangeable set

Chr (x)

Converts an integer to a character.

Unichr (x)

Converts an integer to a Unicode character.

Ord (x)

Converts a character to an integer.

Hex (x)

Converts an integer to a hexadecimal string.

Oct (x)

Converts an integer to an octal string.

View variable data types:

A = 3

Import types

Type ()

Int (a) # convert to an integer

Str (a) # convert to string

Python mathematical functions

Function Return Value (description)
Abs (x) Returns the absolute value of a number. For example, abs (-10) returns 10.
Ceil (x) Returns the upper integer of a number. For example, math. ceil (4.1) returns 5.
Cmp (x, y) If x <y returns-1, if x = y returns 0, if x> y returns 1
Exp (x) Returns the x power of e (ex). For example, math. exp (1) returns 2.718281828459045
Fabs (x) Returns the absolute value of a number. For example, math. fabs (-10) returns 10.0
Floor (x) Returns the rounded down integer of a number. For example, math. floor (4.9) returns 4.
Log (x) For example, math. log (math. e) returns 1.0, math. log (2.0) returns
Log10 (x) Returns the logarithm of x on the base of 10. For example, math. log10 (100) returns 2.0.
Max (x1, x2 ,...) Returns the maximum value of a given parameter, which can be a sequence.
Min (x1, x2 ,...) Returns the minimum value of a given parameter, which can be a sequence.
Modf (x) Returns the integer and decimal parts of x. The numerical symbols of the two parts are the same as those of x, and the integer part is expressed as a floating point.
Pow (x, y) The value after the x ** y operation.
Round (x [, n]) Returns the rounding value of floating point x. If n is given, it indicates the number of digits rounded to the decimal point.
Sqrt (x) Returns the square root of number x. The number can be a negative number and the return type is a real number. For example, math. sqrt (4) returns 2 + 0j.

Python random number Function

Function Description
Choice (seq) Randomly select an element from the element of the sequence, such as random. choice (range (10), and randomly select an integer from 0 to 9.
Randrange ([start,] stop [, step]) Obtains a random number from a set that increments by the specified base number within the specified range. The default value of the base number is 1.
Random () The next real number is randomly generated within the range of [0, 1.
Seed ([x]) Change the seed of the random number generator. If you do not understand the principle, you do not need to set seed. Python will help you select seed.
Shuffle (lst) Random sorting of all elements in a sequence
Uniform (x, y) The next real number is randomly generated, which is within the range of [x, y.

The above discussion about the conversion between Python data types is all the content shared by the editor. I hope to give you a reference and support for the help house.

Related Article

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.