Mar-13-2017, 03:08 AM
(Mar-12-2017, 10:42 AM)ichabod801 Wrote:(Mar-12-2017, 04:43 AM)Skaperen Wrote: it had been my understanding that print() would apply repr() to any non-string argument it got.
It does. The error happens before that point. First it evaluates the argument it gets, then it applies repr. The error comes in the evaluation, when+ listA[i]
tries to add an integer to a string.
Edit: Didn't think it through. print applies str() to any non-string argument it gets. Typing an argument into the interactive console gives the repr().
my bad for blaming it on print(). the OP was building a big string with an int in there and i didn't look at the code close enough to see that. separate args given to print() works, too.
now you guys need to advise the OP what is the best way to code this to avoid that perl-ism mentioned earlier.
Output:lt1/forums /home/forums 2> cat foo.py
# loop in list
listA = list(range(0,101,5))
for i in range(len(listA)):
print('Item no.', i+1, 'is:', listA[i])
lt1/forums /home/forums 3> py3 foo.py
Item no. 1 is: 0
Item no. 2 is: 5
Item no. 3 is: 10
Item no. 4 is: 15
Item no. 5 is: 20
Item no. 6 is: 25
Item no. 7 is: 30
Item no. 8 is: 35
Item no. 9 is: 40
Item no. 10 is: 45
Item no. 11 is: 50
Item no. 12 is: 55
Item no. 13 is: 60
Item no. 14 is: 65
Item no. 15 is: 70
Item no. 16 is: 75
Item no. 17 is: 80
Item no. 18 is: 85
Item no. 19 is: 90
Item no. 20 is: 95
Item no. 21 is: 100
lt1/forums /home/forums 4>
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.