What symbols are used to separate python statements?

Release: 2019-07-08 09:14:59
Original
8909 people have browsed it

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

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

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

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

4. String constants have special rules

>>> string='''aaa
	bbb
	ccc'''
>>> string
'aaa\n\tbbb\n\tccc'
>>>
Copy after login

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!

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!