Python basic string string details and examples

  • 2020-05-27 06:25:26
  • OfStack

Python string (string) details and code

Python strings can use single quotes ('), double quotes ("), and 3 quotes (" "); Inside the quotation marks (" "), you can add single and double quotation marks, or you can add them by escaping the sequence (\);
String placed in 1 automatically concatenate into 1 string;

Add the qualifier R or r to the string to indicate a natural string (nature string).

Add "\" at the end of the physical line to connect the next physical line. Parentheses, square brackets, and braces can also extend physical lines to a definite limit;

See code comments for details;

The code is as follows:

# -*- coding: utf-8 -*- 
#Author: Wendy 
#Date: 2013-12-03 
#eclipse pydev, python3.3 
#3 Quotation marks are free to use double quotation marks ("") And single quotes ('') 
s = ''''' I am a girl and like heels. 
Hello, "python" sister. ''' 
# Escape sequences "\" 
st = '''''Hello, girls, l like (\'''). ''' 
# The string is placed 1 Automatic connection  
sa = 'Girls are ''the best. ' 
#r Representing a natural string ,  There is no escape (\n) 
sr = r"nature is good. \n {0}" 
#"\" Represents the connection string  
sc = 'Oh, the lines are too \ 
# parentheses ,  The square brackets ,  Curly braces ,  You can limit the range ,  You don't have to escape  
print("the braces can do {thing}.". 


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, I hope to help you, thank you for your support of this site!

Related articles: