Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What points should Xiaobai keep in mind when learning python?

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains what points Xiaobai should keep in mind when learning python. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn what points Xiaobai should keep in mind when learning python.

1. Initial change

In Python, a name in an expression cannot be used until it is assigned. This is intentional: it avoids some typing errors and also avoids the question of what the default should be. Remember to initialize the counter to 0, initialize the list to [], and so on.

2. Start from the first column

Be sure to start with the top-level, unnested code in the leftmost first column. This includes code that is not nested in the module file, and code that is not nested in the interaction prompt. Python uses indentation to distinguish between nested code segments, so the space to the left of your code means nested code blocks. Spaces are usually ignored except for indentation.

3. Indent consistent

Avoid mixing tab and spaces to indent in the same block of code unless you know how the system running your code handles tab. Otherwise, it looks like an indentation of tab in your editor. Maybe Python will look like some white space. To be on the safe side, every block of code is indented with tab or spaces; it's up to you to decide how much to use.

4. Use parentheses when calling a function

Whether a function requires arguments or not, you must add a pair of parentheses to call it. That is, use function () instead of function. The function of Python is simply an object with a special function (call), which is triggered by parentheses. Like all objects, they can be assigned to variables and use them indirectly: x=function:x ().

In Python training, such errors often occur in the operation of files. It is common to see a novice close a problem with file.close instead of using file.close (). Because it is legal to reference a function in Python without calling it, the operation without parentheses (file.close) is silently successful, but the file is not closed!

5. Do not use expressions or paths in Import

Use the folder path or file extension on the system's command line, but not in the import statement. That is, use import mod instead of import mod.py, or import dir/mod.py.

In practice, this is probably the second most common mistake made by beginners. Because modules have suffixes other than .py thinks (for example, .pyc), forcing a suffix to write is not only ungrammatical, but also meaningless.

At this point, I believe you have a deeper understanding of what points Xiaobai should keep in mind when learning python. You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report