How to type three quotes in python

coldplay.xixi
Release: 2023-01-03 09:28:02
Original
34782 people have browsed it

How to type python triple quotes: 1. Directly use three backslashes to escape; 2. Create a new module and enter [a = "\""print(a a a)] in the module; 3 , use the ord function to obtain the ASCII encoding value of a character.

How to type three quotes in python

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

How to type python triple quotes:

1. The first method is relatively simple, just use three backslashes to escape, that is:

print("\"\"\"");Because \" represents a quotation mark, then three consecutive \" are naturally triple quotation marks.

How to type three quotes in python

2. The second method is a little more verbose. Print three quotes through variables and create a module through "File" -> "New File" in the menu bar.

How to type three quotes in python

3. Enter in the module:

a = "\""print(a + a + a)
Copy after login

Confirm, save, and then run.

How to type three quotes in python

4. The effect is the same as using print("\"\"\""); directly on the command line.

How to type three quotes in python

5. The third method is a bit circuitous, printing through character encoding. Because any information is saved in the form of data in the computer, strings are no exception. , since it is data, it must have a value, and the same is true for characters. In python, you can use the ord function to get the ASCII encoding value of a character. For example, ord("\"") can get the ASCII encoding of the quotation mark, which is 34.

How to type three quotes in python

6. Then you can use the chr function to convert the numeric value to the character corresponding to the value. We save it through a variable and then print it three times in a row through print, or directly Add the variables three times and print them, like this:

>>> a = chr(34)>>> s=a + a + a>>> print(s)"""
Copy after login

How to type three quotes in python

Related free learning recommendations: python video tutorial

The above is the detailed content of How to type three quotes in python. 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!