Home >Backend Development >Python Tutorial >What symbols are used to separate python statements?

What symbols are used to separate python statements?

尚
Original
2019-06-29 09:50:218974browse

What symbols are used to separate python statements?

Python statement separation: You can use syntactic bracket pairs. The statements in the bracket pairs can span several lines. You can also use backslash endings to have the same effect. You can also use parentheses. To separate, character constants have special rules and can be separated by three pairs of single quotes.

1. If you use syntax bracket pairs, the statement can span several lines

List:

>>> a=[2,3,4]
>>> b=[1,
       2,
          3,]
>>> a
[2,3,4]
>>> b
[1, 2, 3]
>>>

Dictionary:

>>> c={'a':1,'b':2,'c':3}
>>> d={'a':1,
             'b':2,
                   'c':3}
>>> c
{'a': 1, 'b': 2, 'c': 3}
>>> c
{'a': 1, 'b': 2, 'c': 3}
>>> d
{'a': 1, 'b': 2, 'c': 3}
>>>

2. If you use reverse With a slash at the end, the statement can span several lines

>>> if 2>1 and \
    2>0:	
        print(True)	
True
>>>

3. This method of use is not recommended because it is easy to make errors

We recommend using parentheses

>>> if (2>1 and 
    2>0):
	 print(True)
	
True
>>>

4. String constants have special rules

>>> string='''aaa
	bbb
	ccc'''
>>> string
'aaa\n\tbbb\n\tccc'
>>>

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What symbols are used to separate python statements?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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