Learn two python---strings

Source: Internet
Author: User

Strings can be represented by single quotation marks (' ... ') or double quotation marks ("..."), and \ can be used to escape quotation marks;

Case one: If there is no single quotation mark in the string and only double quotation marks, it is quoted in single quotation marks, otherwise it is quoted in double quotation marks.

For example, to print:

Doesn ' t: >>> "doesn ' t"

"Yes", he said >>> ' yes ', he said '

Alternatively, use the escape symbol \

Doesn ' t: >>> ' doesn\ ' t '

"Yes", he said >>> "\" yes\ ", he said"

Scenario Two: What happens if the character preceded by \ is treated as a special character? Add an R before the first quotation mark

>>>print ' C:\some\name ' c:\someame

In the example, \ n is considered a newline symbol, then the first quotation mark is preceded by R:

>>>print R ' C:\some\name ' C:\some\name

Scenario Three: The string wants to be divided into multiple lines, how to do?? Use "" "..." "" or ' ... '


Scenario four: How to concatenate multiple strings together??
(1) can use + (variable + string text also applies)

>>> ' app ' + ' le ' apple '

(2) Adjacent automatic connection (for two all string literals)


Scenario Five: How does a string be intercepted (retrieved)? Use subscript

Scenario Six: Want to change a character in a string, what to do??
WORD[1] = ' A ' This is not going to work!!!

Learn two python---strings

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.