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 in Python by Chetan
23 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 by Omkar
• 67,660 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
38 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 ariaholic
• 7,340 points
108 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 in Python by rajesh
• 1,210 points
79 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
125 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 337 views
+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
• 67,660 points

edited Aug 8, 2018 by Omkar 1,135 views