Python some built-in functions

Source: Internet
Author: User

chr (i) returns a single string corresponding to an integer in the ASCII code. For example, CHR (97) returns the string ' a '. Just the opposite of Ord. The parameter must be in the range [0..255],UNICHR (i) is the Unicode version of Chr.

Hex () can only convert integers

Int (x, [base]) acts: Converts a string of a number or base type to an integer. int (x=0) int (x, base=10), the base default value is 10, which means that when the value of base is not specified, the function will handle x as decimal. Note: 1. X can be either a number or a string, but base is assigned a value of x to only the string 2. x must be a base type when it is a string, that is, when x becomes a number, it must be represented as a base binary

bin () Returns a binary representation of an integer int or long int.

The eval () function is used to execute a string expression and return the value of the expression.

Syntax: eval  (expression[,   globals[,   locals ]])

Expression--expressions.

Globals--variable scope, global namespace, if supplied, must be a Dictionary object.

Locals--variable scope, local namespace, if provided, can be any mapping object.

The Pow () method returns the value of XY (the y-square of X)

raw_input () treats all input as a string and returns the string type.

Note that both input () and raw_input () functions can receive strings, but raw_input () directly reads the console input (any type of input it can receive). For input (), it wants to be able to read a valid Python expression, that is, you must enclose it in quotation marks when you enter a string, or it will throw a syntaxerror.

Unless there is a special need for input (), it is generally recommended to use raw_input () to interact with the user.

Note: Python3 input () defaults to the type of STR received.

The range () function creates a list of integers, which are typically used in a for loop.

Syntax: Range(start, stop[, step])      

Start: Count starts from start. The default is starting from 0. For example, range (5) is equivalent to range (0, 5);

End: Count to end, but do not include end. For example: Range (0, 5) is [0, 1, 2, 3, 4] No 5

Step: Step, Default is 1. Example: Range (0, 5) is equivalent to range (0, 5, 1)

Hash () is used to obtain a hash of an object (string or numeric value, etc.).

The ID () function is used to get the memory address of the object

The max () method returns the maximum value of a given parameter, which can be a sequence

The tuple () function converts a list to a tuple.

Python some built-in functions

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.