Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Answer: A Solution: Essentially we are calling func and printing it's return value. So let's work out what func is doing. lst, lst2 = [7], [7] is a tuple assignement lst is assigned [7], and lst2 is assigned [7] lst3 = lst *2 repeats lst twice, ie, [7, 7], assigns to lst3 +
Finally we come to the return statement. Let's be careful here. The return value is lst3 == lst2.extend([lst]) The left-hand-side of the comparison is lst3, [7, 7]. The right-hand-side is lst2.extend([lst]) which is equivalent to lst2.extend([[7]]) Now the extend method +
changes lst2 *in-place*. BUT it returns None. So, for the purpose of comparison, the result of the extend operation is None. Therefore the return value is [7, 7] == None which is False and that's what gets printed.
The biggest React event in France just dropped its speaker lineup. You’ll want to see this.
United States 트렌드
- 1. Steelers 66.8K posts
- 2. Steelers 66.8K posts
- 3. Jags 14.1K posts
- 4. Ravens 23.3K posts
- 5. Derrick Henry 3,218 posts
- 6. #HereWeGo 8,607 posts
- 7. Broncos 34.5K posts
- 8. Goff 8,273 posts
- 9. Aaron Rodgers 8,406 posts
- 10. #OnePride 5,228 posts
- 11. Hunter Henry N/A
- 12. Boswell 3,232 posts
- 13. Contreras 9,222 posts
- 14. Mike Tomlin 3,354 posts
- 15. DK Metcalf 12.9K posts
- 16. #PITvsDET 4,846 posts
- 17. #DUUUVAL 4,397 posts
- 18. Raiders 27.3K posts
- 19. Jaguars 27.8K posts
- 20. Dan Campbell 2,430 posts
Something went wrong.
Something went wrong.