Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching Strings and Operators

Regarding "i" *20 why its works and "i" +20 not equal to i20 and error ?

Regarding

"i" *20 why its works and "i" +20 not equal to i20 and error ?

2 Answers

Python can not concatenate a string and an integer. They are considered two separate types of object. "i"*20 concatenates strings (20 i's). "i" + 20 attempts to concatenate a string and an integer. To get that to work you would have to convert 20 to a string "i" + str(20).

THANKS

marin stefan daniel
marin stefan daniel
5,422 Points

"i" * 20 is multiplying the string "i" 20 times "i" + 20 doesn't work because "i" is a string and 20 is a int .. you can not concatenate a string with a int nor add a int (number) with a sting . you can "i" + "20" so it will print "i20" ..meaning the 20 ..must be with "" so it will become a string as well