Python 2, string Learning

Source: Internet
Author: User

The Python language contains six built-in sequences. There are two main types: List and metadata. The list can be modified, but the tuples cannot. If you want to add or delete some elements, you can only use the list. To restrict some elements, you will use the tuples. In general, the list can replace tuples. In the list, there are indexes, shards, adding, multiplication, and so on.

The following defines a variable to store a string:


The print display and direct pystr [0] display objects are different. You may find that the printed string is enclosed in single quotation marks when it is displayed. All strings printed using Python are enclosed in quotation marks, because the value is maintained during Python printing.CodeStatus, rather than the status you want the user to see. Here we discuss two mechanisms for converting values into strings:

STR function: converts a value to a valid string for your understanding.
Repr function: Creates a string that represents the value in a valid Python expression.



If you want to write a long string that must span multiple rows, you can use three single quotes to forcibly wrap the string with a backslash \

 
>>> ''' Asdghagjawag''' asdgh \ nagjaw \ nag '>>> 1 + 5 ++ 6 >>>

In python, multiple backslashes (commonly used in paths) are escaped by adding \. You can add r before the entire string:

Common functions:
ABS (number): Absolute Value Function
Cmath. SQRT (number): the square root of a negative number. The cmath library must be introduced.
Float (object): Floating Point Operation
Help (): A Help function that can be used to query the help of some functions.
Input (prompt), raw_input (): input is an output statement that returns a variable. A value, string, or number is returned according to the actual situation.
Value. Then, the interpreter will execute the following code based on this value. Input different values will have different return values, and the output results may be different. Input
The input type is different from raw_input.

INT (object ):
Long (object ):
Math. Ceil (number) (returns the upper integer ):
Ath. Floor (number) (returns the following integer ):
Pow (x, y): power operation, the power of X to Y
Repr (object), STR (object): String output. Note the difference. It is mentioned above.
Round (number [. ndigits]): Rounding the function. Import math is required.

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.