Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

PythonPr's tweet image. 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


Error - Can only concatenate strings


Error, can’t “add” strings and integers.


D, Error, only string


When something so simple causes doubts about the possible results means this is not a good tool for working.


Error. String concatenation(+) can’t work for integers.


Going for Error


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.


D. you can't concatenate strings with integers


Rules of concatenation applies here, the answer is D)


United States Tendenze
Loading...

Something went wrong.


Something went wrong.