Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Answer: D (Error) Common beginner mistake! "6" in quotes is a string, not a number. Python won't mix types automatically. Fix it: - Need number? int("6") + 3 = 9 - Need string? "6" + str(3) = "63" Always match your types!
If I'm reading it correctly, the answer is b. 6 3 because 6 is a text and 3 is a number
When something so simple causes doubts about the possible results means this is not a good tool for working.
Answer :- Error(D) Because a is string and 3 is integer So first convert 3 in a string by str(3) Now the output is 63
Well, the correct answer is D Error, as Python's + operator performs string concatenation on strings or arithmetic on numbers and would require explicit conversion like int(a) + 3 for a numeric result of 9.
United States Tendenze
- 1. Penn State 22.9K posts
- 2. Indiana 38.2K posts
- 3. Mendoza 19.8K posts
- 4. Gus Johnson 6,599 posts
- 5. #iufb 4,139 posts
- 6. #UFCVegas111 4,537 posts
- 7. Sayin 67.8K posts
- 8. Omar Cooper 9,373 posts
- 9. Estevao 37.1K posts
- 10. Iowa 19.3K posts
- 11. Sunderland 153K posts
- 12. Mizzou 3,597 posts
- 13. Texas Tech 13.6K posts
- 14. Jim Knowles N/A
- 15. Kirby Moore N/A
- 16. Happy Valley 1,878 posts
- 17. James Franklin 8,533 posts
- 18. Oregon 33.4K posts
- 19. Carter Smith N/A
- 20. Zollers N/A
Something went wrong.
Something went wrong.