Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
49
13
202
39.5K
Jenny
Jenny@JennyTheDev·
@PythonPr a) 20 int("10") converts the string to integer 10, then 10 + 10 = 20. The trap is option b), that would happen with str concatenation (str(x) + y = "1010"), but here int(y) makes it math, not string magic.
English
0
0
25
3.7K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output 20 Why: x = 10 is an integer y = "10" is a string int(y) converts "10" → 10 (integer) So x + int(y) becomes 10 + 10 = 20 and print(...) outputs 20
English
0
0
9
3.3K
Ranjan
Ranjan@Ranjanrgdev·
@PythonPr 20 Y is converted to int
English
0
0
6
1.8K
Trisha 479
Trisha 479@trisha51972·
@PythonPr A.20 String is converted to an integer before addition
English
0
0
3
945
Evil_Hunter
Evil_Hunter@imsmartVik·
@PythonPr int converts string value into integer then adds 2 integer value output :20
English
0
0
2
753
Piyush Raj
Piyush Raj@tiwarycode27·
@PythonPr Y is a string with "" , and while printing u r converting it into int , but still I don't understand how the answer is 20? It can also convert it to any garbage values ?
English
0
0
0
177
Melo
Melo@Tumelo_Zonke·
@PythonPr 20 because you convert the string into an integer
English
0
0
0
446
Paylaş