How can I change indentation in pycharm to only 2 spaces instead of 4? My team follows the pep8, but chose to use 2 spaces instead of four, and I can't find anywhere to change it.
While in the editor, select the necessary code fragment and press Ctrl+Alt+I . If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.
ctrl + shift + A => open pop window to select options, select to spaces to convert all tabs as space, or to tab to convert all spaces as tab.
Python doesn't care, as long as you're consistent. So if you start using four spaces for your indent, you always need to use four spaces. For example, in this snippet of code, we can see that the first indent has four spaces, but the second indent has only two. And you can see that the code doesn't line up.
You can select the following options: Leading: select this checkbox to add whitespaces before your code line. Inner: select this checkbox to display whitespaces inside the line of your code. Trailing: select this checkbox to display whitespaces after the code line.
File -> Settings -> Editor -> Code Style -> Python (or "General" for all text files) -> Tabs and Indents (tab).
And there is a search tool in the top left corner of the settings window. You can use it to search any IDE setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With