How does integer casting work? int() [solved]

Have we learned int concatenation in this course yet?. Maybe I’m wrong but I thought we only learned str concatenation so far.

There is no such concept as int concatenation. int is not treated as character data but as numeric. We add numbers, and concatenate character sequences (strings).

 "string" + " concatenation" => "string concatenation"

What may appear as concatenation in the above post is actually addition of two numbers, even though they don’t look like it. Their expressions boil down to two numbers added together to give an index.

Oh thats my mistake I meant int casting

Consider it not unlike str casting.

123 => str(123) => '123'

'123' => int('123') => 123

We can also use the constructor to reduce floats to ints…

123.4 => int(123.4) => 123

Ah yes I understand it now. My issue was that I couldn’t solve the problem without that information so maybe it should be part of the course before this question. Thank you though I get it now!

Where does this challenge fit in to the course flow (i.e., which units precede this)?

Consider challenges as a way to determine how ambitious a learner has been leading up to them. It is not uncommon for new concepts to arise during the solving of a problem. On the whole, there is no crime in skipping the challenge until later if one feels there is too much missing information.

This is at the end of Learn Python: Lists. Oh I see, I thought the course was intended to be learned in order. I see that the hint explains a bit about int casting but it does not explain how it chops off the decimal (instead of maybe rounding for example) which was confusing for me. I personally don’t see much benefit in being given problems I don’t have the tools to solve but you are totally right that I could just skip it and come back later. I will do that for any later problems. Thank you again for helping and replying so quickly.

2 Likes