Python language usage skills

高洛峰
Release: 2017-03-02 15:52:28
Original
1315 people have browsed it

The following editor will bring you a sharing of python language usage skills. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

It’s best to specify the path of python before writing:

# !/usr/bin/python

python needs to add encoding method in linux: to avoid Chinese garbled characters

# -*- coding: UTF-8 –*-

2 Among all kinds of languages, python should be the language that knows how to use indentation the most. Even if its for statement has multiple lines, you don’t need to think about java. It can be used in the same way as C++ and c. {}, like js and swift, can represent a sentence with a newline character instead of using the ; sign. Students with language background, please note:

In python’s view:

Python language usage skills

Python language usage skills

If the indentation method is changed, for example, indenting on the second for, it will cause an error:

Python language usage skills

The error that occurs is as follows:

Python language usage skills

So here comes the question: What impact do line breaks and indentation have on python? ? ?

Python language usage skills

It can be seen from the running results:

Python language usage skills

1 Newline can be regarded as the ; sign in java and c++, not It will affect the structure of the statement.

2 Indentations with the same distance can be regarded as a pair of {}, and {} should appear in pairs in any language.

The reason why this python statement appears in demo1

Python language usage skills

is equivalent to:

Python language usage skills

It’s because {} does not match. That’s why the following error occurs

IndentationError: unexpected indent

Or it can be understood this way: statements with the same indentation can be regarded as code blocks{}

The above article The sharing of Python language usage skills is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more articles related to python language usage skills, please pay attention to 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!