WHY does Code have to be indented in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

WHY does Code have to be indented in Python?

Why does code in python have to be indented.its just annoying.Cant Python just read a block of code.?

11th Feb 2018, 11:29 AM
🅿️®️⭕️_e✖️e
🅿️®️⭕️_e✖️e - avatar
2 Answers
+ 3
other programming laquages use { code } where python uses indentation. Some way or an other you need to tell where a function, loop, ... begins and ends. Try this: n =1 list = [1,2,3] for i in list: n = n*i print(n) # outputs 3 numbers for i in list: n = n*i print(n) # outputs 1 number
11th Feb 2018, 11:49 AM
davy hermans
davy hermans - avatar
+ 1
The syntax of Python requires indentation. If you really want the {code} syntax, try typing from __future__ import braces in your interpreter and see what it tells you...
11th Feb 2018, 5:34 PM
Amaras A
Amaras A - avatar