Python string Definition _python

Source: Internet
Author: User
For example: ' String ', ' string ', ' ' ' ' string ' ', ' or ' '.
In use, single and double quotes are no different. The main function of triple quotes is to include line wrapping in a string. In other words, the string in three quotes, if the content in the program is a branch, then, in use is also a branch. This does not need to be displayed using "\ n" to wrap the line.

Like most programming languages, strings in Python are immutable. Similarly, the processing of transfer characters is similar to other languages. such as "' What ' your name?" ", within this string, there is a" ' "character, which can be transferred using the ' \ ' character for this character: ' what\ ' your name? ', or use double quotes instead of the string definition:" What ' your name? ". The usual way is to use ' \ ' to transfer characters. You can use ' \ n ' to define a newline, ' \ t ' means a tab, ' \ \ ' to represent a real ' \ ' character.

For strings, there is a very useful format method. The main purpose of this method is to replace the ugly "+" string connection. For example, "My name is {0}". Format ("un"), the true value of this string is the "My name is the United Nations". This allows you to replace the contents of this string at run time. You can also substitute the form of a named parameter, for example: "My name is {name}". Format (name= "un").

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.