0

Space in python

Hello! i want ask that when we write things in python like for num in range(1,1000): print(num) 👆 why need to put 4 space? and when need to put it? please tell me below.

5th May 2018, 3:52 AM
Ayaan
3 odpowiedzi
+ 5
Indentations are enforced in Python to group blocks of codes together. Mainly used in composing functions, conditional blocks, loops, etc. The number of spaces you use for indentations has to be the same for lines grouped within the same block. In other programming languages, curly braces are used in place: if (condition) { // do something } Python: if condition: # do something
5th May 2018, 3:58 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Rule of thumb: when a line of code finishes with a colon, then 'at least the following line is intendated.
5th May 2018, 7:07 AM
Johannes
Johannes - avatar
+ 1
Donna you are wrong, write code look at above and don't give space and you got "IndentationError"
5th May 2018, 4:02 AM
Ayaan