number = 0
for number in range(10):
number = number + 1
if number == 5:
break # break here
print('Number is ' + str(number))
print('Out of loop')
question
why we are using “str(number)” it 2 nd last line
number = 0
for number in range(10):
number = number + 1
if number == 5:
break # break here
print('Number is ' + str(number))
print('Out of loop')
question
why we are using “str(number)” it 2 nd last line
if they wouldn’t converted it into string then an error would be shown because of + operator
You wouldn’t be able to concatenate an int with a str which is why you convert it.
you can keep it as an integer if you removed the “+” and placed “,” instead