Detailed explanation of strings in Python basics

PHPz
Release: 2017-04-02 13:38:41
Original
1113 people have browsed it

PythonString can use single quotes ('), double quotes ("), triple quotes ('''); inside triple quotes ('''), You can add single quotes and double quotes, or you can add them through escape sequences (\);
Strings are put together and automatically concatenated into one string;

Add the qualifier R in front of the string or r, which means it is a natural string (nature string), and the format restrictions inside can be ignored;

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

For details, please refer to the code comments;

# -*- coding: utf-8 -*-
  
#====================
#File: abop.py
#Author: Wendy
#Date: 2013-12-03
#====================
  
#eclipse pydev, python3.3
  
#三引号可以自由的使用双引号("")和单引号('')
s = ''''' I am a girl and like heels.
Hello, "python" sister. '''
  
#转义序列"\"
st = '''''Hello, girls, l like (\'''). '''
  
#字符串放在一起自动连接
sa = 'Girls are ''the best. '
  
#r表示自然字符串, 不会进行转义(\n)
sr = r"nature is good. \n {0}"
  
#"\"表示连接字符串
sc = 'Oh, the lines are too \
large'
  
#括号, 方括号, 大括号, 可以限定范围, 不用使用转义
print("the braces can do {thing}.".
   format(thing="lady"))
  
print(s)
print(st)
print(sa)
print(sr)
print(sc)
Copy after login

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
Copy after login

The above is the detailed content of Detailed explanation of strings in Python basics. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!