Chapter 3 of python Learning

Source: Internet
Author: User

1. String formatting: % is used. Put the string to be formatted on the left side of %, and put the value to be formatted on the right side. If you want to format multiple values, the delimiter uses tuples or dictionaries. However, the list or other sequences cannot be used because the sequence is interpreted as a value. Only tuples and dictionaries can format more than one value. To include a percent sign in a string, you must use %. If the tuples to be converted exist as part of the conversion expression, they must be enclosed in parentheses: >>> '% s plus % s equals % s' % (, 2) ==> '1 plus 1 equals 2 '.
2. String method: (1) find method: search for a substring in a long string and return the leftmost index of the position of the substring. If not found,-1 is returned. You can also provide the second and third parameters of the find method to indicate the start and end points of the search (including the first index, excluding the second index ). Www.2cto.com
(2) join method: inverse method of the split method. It is used to add elements to the queue. The connector is in front, and the queue to be connected is the parameter of the join method. All queue elements to be added must be strings.
(3) lower method: return the lower case of the string.
(4) title method: uppercase letters and lowercase letters.
(5) replace method: returns the string obtained after all matching items of a string are replaced.
(6) split method: the inverse join method, which is used to split strings into sequences. If no separator is provided, all spaces (spaces, tabulation, line breaks, etc.) are used as separators.
(7) strip Method: returns a string that removes spaces on both sides (excluding internal spaces. You can also specify characters to be removed and column them as parameters.
(8) translate method: some parts of the string can be replaced, but this method only processes a single character and can be replaced at the same time.
Author uohzoaix

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.