Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Indentation | The basics
Learn Python from Scratch
course content

Зміст курсу

Learn Python from Scratch

Learn Python from Scratch

1. The basics
2. Arithmetic operations
3. Common data types
4. Conditional statements
5. Other data types
6. Loops
7. Functions

Indentation

Python is easy about rules, but indentation is one of the few rules Python requires to observe.

All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).

HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).

Example of a valid code:

123
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
copy

Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.

123
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
copy

Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).

Завдання

Analyze the code snippet on the right and fix it

Завдання

Analyze the code snippet on the right and fix it

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 1. Розділ 5
toggle bottom row

Indentation

Python is easy about rules, but indentation is one of the few rules Python requires to observe.

All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).

HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).

Example of a valid code:

123
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
copy

Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.

123
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
copy

Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).

Завдання

Analyze the code snippet on the right and fix it

Завдання

Analyze the code snippet on the right and fix it

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 1. Розділ 5
toggle bottom row

Indentation

Python is easy about rules, but indentation is one of the few rules Python requires to observe.

All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).

HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).

Example of a valid code:

123
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
copy

Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.

123
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
copy

Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).

Завдання

Analyze the code snippet on the right and fix it

Завдання

Analyze the code snippet on the right and fix it

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Python is easy about rules, but indentation is one of the few rules Python requires to observe.

All lines in a simple Python program should start at character 0 in every line (no tabs or spaces before code).

HOWEVER, certain blocks of code should use Indentation. The most common blocks that require Intentation are: conditional statements, functions and loops (more on this in the following chapters).

Example of a valid code:

123
#Example of valid code: print("Hello, world!") print("What a beautiful day!")
copy

Below is example of invalid code, it will throw on error (feel free to try). When you try to execute this program you will see error "IndentationError: unexpected indent", this means you broke the Indentation rules and need to fix it to execute the program.

123
#Example of invalid code: print("Hello, world!") print("What a beautiful day!")
copy

Please note that empty lines are simply ignored. Use empty lines to separate code into blocks (make it more readable).

Завдання

Analyze the code snippet on the right and fix it

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 5
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt