Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the default code snippets in Pycharm

Shulou Source: shulou.com Published: 2022-06-01 03:55:08 10月01日 Update

This article mainly shows you "what are the default code snippets in Pycharm", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and learn what are the default code snippets in Pycharm.

There are already some code snippets by default in Pycharm, as follows:

Menu "File"-> Settings, enter the settings interface

Click "Editor"-> "Live Templates" on the left to enter the real-time template interface.

Click on the Python bar and you can see many default code snippets

Let's look at how to use code snippets to implement a small example. Use deduction to filter some values from a list. Look at the moving picture below.

I didn't use a mouse the whole time.

When I finish the first line, how do I go straight to the second line? Press shift+enter, and you can.

Through the code snippet "compgi", you can generate a deductive code snippet. Press the tab key to jump in different areas.

Note that Pycharm also allows you to choose which sequence variable to use when the code snippet is generated.

Sometimes we need custom code snippets. Look at the following picture:

Menu "File"-> Settings, enter the settings interface

Click "Editor"-> "Live Templates" on the left to enter the real-time template interface.

In the template content, use the $variable $to define replaceable places in the template.

On the right button "Edit variables", you can enter the variable settings, you can set the details of each template variable, such as the default value, for example, you can set the variable for the user to choose.

After setting up, click "OK" and you can use it. See how it works.

Using type hints, get a smart hint for variable types

Many times when we define a method, we will find that we can't get any useful intelligence when using a parameter in the method. This is because the variable definition of Python does not need to indicate the type, so IDE cannot speculate what type it is. The figure below is as follows

We can get smart tips by tag type, and the latest version of Pycharm is fully supported. As follows

You can label the type as long as you add: variable type after the parameter.

You can see that the parameter df can now get the correct type of IntelliSense.

Pycharm has a modification prompt function, which can simplify some operations.

The example here is the parameter in the method, but it is also feasible for variables, so I won't give an example here.

These are all the contents of the article "what are the default code snippets in Pycharm?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code variables types templates prompts content parameters intelligence interfaces methods articles examples real-time menus learning help generation selection different feasible Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Apple Shulou Information Microsoft