Python-Based string description and examples, pythonstring

Source: Internet
Author: User

Python-Based string description and examples, pythonstring

Python string (string) Explanation and code

Python strings can be enclosed in single quotes ('), double quotation marks ("), and triple quotation marks ('''). Single quotes and double quotation marks (''') can be added, you can also add the escape sequence;
Strings are automatically connected together to form a string;

The separator R or r is added before the string, indicating that the string is a natural string. The format restrictions can be ignored;

Add "\" at the end of the physical line to connect to the next physical line. Brackets, square brackets, and braces can also expand the physical line to a certain extent;

For more information, see code comments;

The Code is as follows:

#-*-Coding: UTF-8-*-# = # File: abop. py # Author: Wendy # Date: 2013-12-03 #==============================#eclipse pydev, python3.3 # Double quotation marks ("") and single quotation marks ('') s = ''' I am a girl and like heels. hello, "python" sister. ''' # Escape Sequence "\" st = ''' Hello, girls, l like (\'''). ''' # the string is put together to automatically connect sa = 'Girls are ''' the best. '# r indicates a natural string and does not escape (\ n) sr = r "nature is good. \ n {0} "#" \ "indicates the connection string SC = 'oh, the lines are too \ large '# brackets, square brackets, and braces. the range can be limited, do not use escape print ("the braces can do {thing }. ". format (thing = "lady") print (s) print (st) print (sa) print (sr) print (SC)

Output:

the braces can do lady.  I am a girl and like heels. Hello, "python" sister.  Hello, girls, l like (''').  Girls are the best.  nature is good. \n {0} Oh, the lines are too large 

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

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.