Python Raw string

Source: Internet
Author: User

1 str1='let's go'2   "<input> ", line 13     str1='s Go'4               ^5 syntaxerror:invalid syntax

Because str1 inside has "'", so the compiler can not escape and error, the correct code is as follows

str1='let\ ' Go'str1' Let'sgo '

Use \ as escape character to escape symbols in a string

1 str2='C:\now'2str23'C:\now ' 4 Print (STR2) 5 C: 6 ow

Because the str2 inside is the escape character of the line break, the output is wrapped, and the original string escape characters R can be used.

Str2=r'C:\now'print(str2) C:\now

The backslash cannot be at the end of the string.

Str2=r'c:now\ '  <input>', line 1    str2=r'  c:now\ '                 ^

So the compiler will think \ as an escape character escapes ', you can write this

1 str2=r'C:\now'+'\ \'2 Print (STR2) 3 C:\now\

Python Raw string

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.