Basic Python coding practical advice interpretation

Every day you should work hard to improve your coding skills. Today I have brought some programming suggestions to Python novices.

Python language

Open the Python interactive terminal and run the following command

Then the command will have some output, read it carefully because it is really important to Python programmers.

Use this command to empty your Python interactive terminal

When you use the Python interactive terminal to test the code, the content on your screen is getting more and more, and slowly it starts to affect your thinking, then you want to clear the previous output. Commanding clear on a Unix-like operating system can clear the contents of the screen.

This system command can be executed using the Python standard library os.

The following line of Python commands can empty the contents of a Python terminal on a Unix-like operating system.

The windows system can use the cls command to clear the contents of the terminal screen. Since Python's os library methods are cross-platform, the same applies to Windows, so you can clear the contents of the Python interactive terminal in Windows in the Python interactive terminal as shown below.

Be careful when creating tuples

Many people think that the following code will return a tuple. But the actual implementation only knows that it is not the case at all.

After running, the Python terminal actually returns the number 1.

Based on this result, you should easily understand that the parentheses here do not function as tuples, but merely a simple bracket.

If you want a tuple with only one element, how should you write it? Should be like this

Remember to always bring that comma when building a tuple

Test if the variable is in the correct posture of None

You might use the following code to test if the variable is None.

Do not do this. If a is 0, this if judgment cannot be resolved at all. The correct posture should be like this

Get the documentation for a Python object

Getting a documentation of a particular method or module in a Python interactive terminal is very easy, just use the help command.

Run the above command, the interactive terminal will print the document information of the os module, the output is similar to the following

This help command is especially useful in the absence of a web, and is especially convenient and fast.

Of course, you can also view the documentation for a particular method within a module like this:

As you can see from the help below, the getenv method of the os module is used to get the value of the environment variable. If the environment variable does not exist, it returns None.

Exchange variable value

Exchanging variables in Python is easier than any other language and is extremely intuitive

in conclusion

No matter what language you learn, practice is the best way to improve. It is also a mistake! If you have not experienced the experience of making mistakes, you never know what the right path is.

Heat Pipe

Floor heating pipe refers to a pipe used as a circulating flow carrier of low temperature hot water in the ground radiation heating system of low temperature hot water.

Floor heating pipe refers to a pipe used as a circulating flow carrier of low temperature hot water in the ground radiation heating system of low temperature hot water.

According to the production mode, crosslinked polyethylene is divided into four types: peroxide crosslinking (PE-XA), silane crosslinking (PE-XB), electron beam crosslinking (PE-XC) and azo crosslinking (PE-XD).

Among them, peroxide crosslinking and silane crosslinking are two commonly used crosslinking polyethylene pipe products in China.

Pex Cross Linked Polyethylene has no chemical crosslinking agent and catalyst added in the crosslinking process, and no harmful low-molecular compounds, so it will not pollute the liquid delivered. It is a new generation of healthy and environmentally friendly Crosslinked PE Pipe.Can be used as Heat Pipe and widely used in high-end, precision,HVAC and Water Supply System at High Temperature and High Pressure.

We are the professional manufacturer of Electrical Tapes,Insulating Tape and Cross Linked Polyethylene Water Pipe in China for more than 25 years,if you want to know more information about our company and products, please visit our website.




Heat Pipe,Heat Tube,Heat Shrinkable Pipe,Heat Shrink Tubing Electrical

CAS Applied Chemistry Materials Co.,Ltd. , https://www.casac1997.com

Posted on