If we don't use indentation in if statement then what happens in code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If we don't use indentation in if statement then what happens in code?

Phython

17th Jul 2020, 11:14 AM
Apoorv Bansal
6 Answers
+ 2
Apoorv Bansal Simply you should look at it's advantage To indicate a block of code in Python, you must indent each line of the block by the same amount. The two blocks of code in our example if-statement are both indented four spaces, which is a typical amount of indentation for Python.
17th Jul 2020, 11:21 AM
Piyush
Piyush - avatar
+ 2
Alright. Here a complete (I hope) overview of indentation: https://code.sololearn.com/cT5BRIbkia21/?ref=app
17th Jul 2020, 11:29 AM
HonFu
HonFu - avatar
+ 1
If you don't indent in Python, you'll get an error. (Why don't you try it?)
17th Jul 2020, 11:27 AM
HonFu
HonFu - avatar
0
piyush singh it is not a must. Example: indent = 4 if indent == 4: indent += 4 else: indent *= 5 print(indent) Output ==> 8 The above code would work fine without indentation. It just doesn't follow the PEP rules that's all.
17th Jul 2020, 11:28 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
0
Tomiwa Joseph mentioned in description (about what language he is asking)๐Ÿ‘
17th Jul 2020, 11:35 AM
Piyush
Piyush - avatar
0
piyush singh He just edited it๐Ÿ˜ƒ๐Ÿ˜ƒ
17th Jul 2020, 11:35 AM
Tomiwa Joseph
Tomiwa Joseph - avatar