Python problem about str

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')

why we are using “str(number)” it 2 nd last line

Because number is an integer, you must convert the number to a string to concatenate it with the first part of the string 'Number is '.

1 Like

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