+ 1

Tuple Slicing confusion

A quiz had this command in it. nums = (55, 44, 33, 22) print(max(min(nums[:2]), abs(-42))) The answer is 44 somehow, but isn't the min(nums[:2]) 33? abs(-42) is 42, so it should print 42! I don't understand this yet.

5th Feb 2018, 7:41 PM
David Hughes
David Hughes - avatar
1 Antwort
+ 1
indexing starts at 0 ;nums [:2] is 44 and due to the way u wrote o code min (nums [:2]) IS 44 HENCE max (44, abs (-42)) is 44
5th Feb 2018, 8:13 PM
Tichaona Mtasa
Tichaona Mtasa - avatar