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
54 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
• 69,000 points

Related Questions In Python

0 votes
0 answers
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
58 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
166 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
154 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 752 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
• 69,000 points

edited Aug 8, 2018 by Omkar 2,509 views