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 are the most common Python interview questions?

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the most common Python interview questions". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the most common Python interview questions.

Q: what are the naming rules for Python variables, functions, and classes?

Answer: Python naming conventions play an important role in writing code. Although programs may run without following naming conventions, using naming conventions can provide a more intuitive understanding of what the code represents.

Naming conventions for Python (similar to other programming languages)

(1) it cannot start with a number and cannot appear in Chinese.

(2) the name begins with a letter and contains numbers, letters (case-sensitive), and underscores.

(3) can not contain keywords, see the name to know the meaning.

Let's talk about the naming convention of Python:

1. Class

The first letter of a word is always capitalized, and private classes can begin with an underscore. Such as MyClass.

Class MyClass (): passclass MySchool (): pass

2. Function

Function names are all lowercase, if multiple words are separated by an underscore. In addition, the private function begins with an underscore.

Def my_func (var1, var2): passdef _ private_func (var1, var2): pass

3. Variables

Variable names are preferably lowercase, if multiple are separated by underscores.

Constants are in full uppercase, and multiple words are separated by underscores.

Num = 20this_is_a_variable = 1MAX_NUM = 1000

Additional addition:

Abbreviations:

Full spelling should be used in naming. There are two kinds of abbreviations:

1. Commonly used abbreviations, such as XML, ID, etc., should also be named with only capitalized initials, such as XmlParser.

two。 Names contain long words and abbreviate a word. The conventional abbreviation should be used at this time.

For example:

Function is abbreviated to fn

Text is abbreviated to txt

Object is abbreviated to obj

Count is abbreviated to cnt

Number is abbreviated to num, etc.

Leading suffix underscore

A leading underscore: indicates non-public ownership.

An underscore with a suffix: avoid keyword conflicts.

Two leading underscores: used when naming a class attribute causes a name conflict.

Two prefixes and suffixes are underlined: "demon" (with special graphics) objects or properties, such as _ _ init__ or _ _ file__. Never create such names, but just use them.

Note: there is some controversy about the use of underscores.

Specific naming method

Mainly refers to the system reserved word nomenclature in the form of _ _ xxx__. This naming can also be used in a project, and its significance is that variables in this form are read-only, and class member functions in this form should not be overloaded as much as possible. Such as

Class Base (object):

Def _ init__ (self, id, parent = None):

Self.__id__ = id

Self.__parent__ = parent

Def _ _ message__ (self, msgid):

Among them, _ _ id__, _ _ parent__ and _ _ message__ all adopt the system reserved word naming.

At this point, I believe you have a deeper understanding of "what are the most common Python interview questions?" 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

Development

Wechat

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

12
Report