Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 64

Python Insight

Оглавление

Python uses indentation to differentiate levels of code. Indentation refers to the number of spaces and/or tabs at the beginning of a line of Python code. As we have already seen, function definition uses indentation to indicate what code is within the function. We will use indentation to an even greater degree in the next chapter when we cover control logic and loops, which use different blocks of code. Python 3 does not allow mixing of tabs and spaces for indentation (van Rossum et al., 2001). The recommendation is to use spaces for indenting (specifically four), unless one is working with code that already is using tabs for indentation, in which case tabs should be used consistently for indentation. This reduces the processing of the Python interpreter needed to treat all the possible combinations of tabs and spaces the same. To help visually ensure the proper indentation, text editors such as Notepad++ have features to show white space (spaces and tabs). In Notepad++, you can turn this feature on and off through the menu selections View/Show Symbol and clicking on the selection: “Show White Space and TAB.”

Introduction to Python Programming for Business and Social Science Applications

Подняться наверх