How to solve indentation in the below code?

0 votes

Why the below code is not printing anything in the output but showing indentation error? Also, using braces to separate the code is a better choice than using indentation in python so that we can save some time.

for i in range(5):
if i == 3:
break
print(i)
Feb 9, 2019 in Python by Chetan
47 views

1 answer to this question.

0 votes

Python does not use brackets, it uses indentation to differentiate between blocks. Though sometimes, brackets will make the task is, that is not an option in Python. Your code with the right indentation should look like this:

for i in range(5):
    if i == 3:
        break
   print(i)
answered Feb 9, 2019 by Omkar
• 68,940 points

Related Questions In Python

0 votes
1 answer

How to hide a window in the constructor immediately after creation?

You can use QtCore.QTimer class Example(QWidget):     def __init__(self, app):         QWidget.__init__(self)         QTimer.singleShot(0, ...READ MORE

answered Apr 17, 2018 in Python by anonymous
54 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by Aryya
• 7,350 points
146 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8, 2019 in Python by rajesh
• 1,230 points
131 views
0 votes
1 answer

How to add to the python path in Windows?

You know what has worked for me ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
160 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 625 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 68,940 points

edited Aug 8, 2018 by Omkar 1,941 views