Python string Definition

Source: Internet
Author: User

For example, 'string', "string", "" string ", or '''string '''.
There is no difference between single quotes and double quotes. The main function of the three quotation marks is to include line breaks in strings. That is to say, if the content in the string is ProgramIf it is a branch, it is also a branch in use. In this way, you do not need to use "\ n" to wrap the line.

Like the majorityProgramming LanguageSimilarly, strings in Python are unchangeable. Similarly, Transfer Character Processing is similar to other languages. For example, "What's your name? '", The character"' "appears inside the string. For this character, you can use '\' to transfer: 'What \'s your name? ', Or use double quotation marks instead of string definition: "What's your name? ". It is often used to transfer characters using. You can use '\ n' to define a line break.' \ t' indicates a tab, and '\' indicates a real '\' character.

There is a very useful format Method for strings. The main purpose of this method is to replace the ugly "+" string connection. For example, "My name is {0}". Format ("United Nations"), the true value of this string is "My name is United Nations ". In this way, you can replace the content of this string at runtime. You can also replace it with a named parameter, for example, "My name is {name}". Format (name = "").

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.