Q:

Is indentation required in python?

0

Is indentation required in python?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer : 

Yes, Indentation is necessary for Python. Most of the programming languages like C, C++, Java use braces { } to define a block of code. Python uses the indentation to mark blocks of code. It is one of the distinctive features of Python is its use of indentation to highlighting the blocks of code. Whitespace is used for indentation in Python. If your code is not indented necessarily, it will not execute accurately and will throw errors as well.

# See code indentation 
  
site = 'aticleworld'
  
if site == 'aticleworld': 
    print('Hi aticleworld...') 
else: 
    print('Ohh...') 
print('Please visit Aticleworld !')

Output:

Hi aticleworld…
Please visit Aticleworld !

Code Explanation,

The lines print(‘Hi aticleworld…’) and print(‘Ohh…’) are two separate code blocks. The two blocks of code in our example if-statement are both indented four spaces. Last print(‘Please visit Aticleworld !’) is not indented, and so it does not belong to the else-block.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Interview Questions and Answers

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is self in Python?... >>
<< Is python a case sensitive language?...