Pycharm must have small skills, you don’t need to work overtime if you use it well, and the efficiency doubles

You must use Pycharm to learn Python. Today, I will teach you 11 of the most commonly used skills of Pycharm, as well as some commonly used shortcut keys of Pycharm, so that your writing efficiency can be doubled, and you will not have to work overtime in the future!

Keep up with the speed of the old driver!
insert image description here


1. Common tips

1. Set the code font.

Click "File" in the upper left corner, select "Settings", enter "font" (font) to find "Font", and set the number in "Size", the default is 12, 18 or 20 is recommended That's it.

insert image description here


2. Set the text size of the menu interface

This is a little different from the above. The above is to adjust the text size of the code, but it does not change the text size of the menu interface. If your menu interface text is relatively small, such as this:

insert image description here
Then you need to adjust the text size of the menu interface, click "File" in the upper left corner, select "Settings", enter "font", find "Appearance", and tick "Use custom font", you can Choose the font size you like in the Size behind.

insert image description here


3. Quick multi-line comment or cancel multi-line comment

Although we can use "#" to make single-line comments when writing code, if there are multiple lines of code that need to be commented, it is a bit troublesome to type "#" line by line. Here we can use the mouse to select multiple lines of code, and then press Ctrl+ / You can comment multiple lines of code, and you can also uncomment multiple lines of code.

insert image description here


4. Code formatting, standardizing code

When we first started writing code, it is inevitable that there will be problems with non-standard code writing. Although it does not affect the operation, the readability is relatively low, especially when you read a long and non-standard code. , you will experience the pain.

For example, this irregular writing method will give you a few spaces from time to time.

insert image description here
This problem is actually easy to solve. We only need to find "Code" in the menu bar after writing the code, and click "Reformat Code" to automatically standardize the code.

insert image description here


5. Quickly modify the same variable or class

When writing code, we often have to define many variables or classes. Variables or classes may be used in multiple places when writing code. If we need to modify all the variables or classes in the code, then we are a Amend it everywhere?

Of course not, we only need to select the variable or class that needs to be renamed, right-click and select Refactor from the pop-up option, and then click Rename to make global modifications.

For example, I want to change all "n" variables in the code to "i", then the operation is as follows:

insert image description here


6. Quickly find variables, functions, etc.

When our code is relatively long, it is very troublesome to swipe from beginning to end to find a variable or function. At this time, we need to use the shortcut key Ctrl+f for quick search.

For example, I want to find out where the function "runGame" is used in the Snake project, then we only need to use Ctrl+f to call up the small window, and then enter the keyword "runGame" to search to every occurrence of "runGame" in the code.

insert image description here


7. Find modification history

When writing a project, it is often necessary to modify, and sometimes it takes several days to complete it, but if we open pycharm today to add a new function, we don’t want it after a long time, and want to get back to yesterday’s version, but It's been a long time, and I can't get it back even if I cancel it, what should I do?

At this time, you need to find the modification history. Pycharm is still very user-friendly. Every step of the change you make, it will save the history for you. Just right-click the file and you can find all the changes in the Local History. historic version.

Take the simplest example. For example, my current code has an extra function to "prompt 'execution end' after the execution is completed". I don't need it, but I can't undo it now. What should I do? At this time, we can go to Local History to find the historical version and change the existing version back to the historical version. (Except for direct deletion, which is not our purpose)

insert image description here


8. Install and configure pippy domestic source

When we use pip to install some resources, pycharm will download foreign resources for us by default. Sometimes the installation will fail due to network and other problems. In fact, we can configure it to let it download domestic resources. solved.

The most common way is to go to the open source mirror station of Tsinghua University to download. We only need to set this in pycharm, and it will go to China to download by itself in the future.

Setting method : Click "File" in the upper right corner → click "Settings" → find "Python interpreter" under Project → click "+" → click "Manage Repositories" → click "+" → enter the address of the open source software mirror site of Tsinghua University: https //pypi.tuna.tsinghua.edu.cn/simple

insert image description here


9. Install the package

When writing code to achieve certain functions, we often need to install software packages, so the function of installing packages for pycharm must be mastered.

method:

Click "File" in the upper left corner → click "Settings" → find "Python interpreter" under Project → click "+" → enter the name of the package you want to install, such as "pygame", and then click "Install Package" below to start Installed, the installation is complete and you can use it.

insert image description here
Note that it can only be used after the installation is complete, and there will be a download progress bar at the bottom of the interface:

insert image description here


10. Debugging

It is easy for us to report errors when writing code, but sometimes it is difficult for us to see the problem on the bright side when reporting errors, so we need to debug at this time, which is also a common technique in the development process.

How to debug? Click on the left side of the line of code that you think may go wrong, and a red dot will appear. We call it a breakpoint. As long as the program runs to the breakpoint, it will automatically stop. After setting the breakpoint, we right-click and select "Debug project name" to run, and then we get to the running interface, we walk step by step, and at the same time we can see the changes in the values ​​of some variables inside.

insert image description here

There are also many ways to debug. You can search the Internet for specific debugging skills, so I won’t explain too much here.


11. Set personalized background

This can be regarded as an additional function. You can set a personalized background for your pycharm, depending on your personal needs. If you want to set it, you can set it up. After all, it is tiring to read English and numbers when writing code. It is also possible to read something else occasionally. , such as my girlfriend.

insert image description here
Setting method:

①Open pycharm, click File, and select settings.

②Click Appearance under the Appearance & Behavior option, and click Background Image.

③ Click on the place with "..." in the upper right corner, and you can choose the picture you want to use as the background. After confirming, choose the display method you like. I think the second method is good.

The last thing is to set the brightness of the background image. I suggest that a brighter background with a transparency of 10% is almost the same. If it is too bright, it will affect the code, personal preference and image color.

(Just to clarify, that background is not mine)


2. Commonly used shortcut keys

Finally, I will attach a summary of shortcut keys commonly used by Pycharm for everyone, and I wish you more and more smooth writing in the process of writing code.

insert image description here
Recently, there are too many pirated images and texts, so I can only add watermarks. For those without watermarks, you can chat with me privately, or you can sort out some commonly used ones by yourself.


3. Conclusion

I would like to advise those friends who are not good at English and who are afraid of English software, do not install the Chinese version of the development software because of this. In addition to the stability of the Chinese version without the native English version, there is also a The biggest reason is that most of the mainstream development software now use the original English version. If you have a Chinese version permanently, you will be helpless when you encounter software that you want to use the English version someday.

Just like when we were learning to drive, if you learned automatic transmission, you would not be able to drive a manual transmission one day, but if you learned manual transmission, it would be easy to drive automatic transmission.

insert image description here

Thank you for your reading and liking. I have collected a lot of technical dry goods, which can be shared with friends who like my articles. If you are willing to take the time to settle down and learn, they will definitely help you. The dry goods include:

insert image description here

Click on the business card at the end of the article to take it away
insert image description here

Guess you like

Origin blog.csdn.net/zhiguigu/article/details/130216420