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
36
16
135
17.5K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: A) 20.0 float('15') converts string to 15.0 › 15.0 + 5 = 20.0 For beginners: float + int always returns float.That's why it's 20.0, not 20. Python keeps the decimal even when the result is a whole number.
English
0
0
0
577
OE Bisong
OE Bisong@7thangelos·
@PythonPr A (20.0) The string '15' is stored in the variable num_str. The variable is converted to float (decimal), & added to 5. When you perform arithmetic between a float and an integer, the result is automatically promoted to a float.
English
0
0
0
360
J.Walter Krzaszczak
J.Walter Krzaszczak@JKrzaszczak·
@PythonPr Guys, because he uses float(num_str) the compiler added the .0 if he did print(int(num_str) + 5 the answear would be 20
English
0
0
0
214
Manish Khyalia
Manish Khyalia@Manish_Kumar60·
@PythonPr Answer:-(A)20.0 When you convert a string to a float, it becomes a number. So float('15') is 15.0 and then add 5 makes it 20.0 because In Python, when you add a float and an integer, the result is always a float.
English
0
0
0
217
pks_406
pks_406@pks_406·
@PythonPr The answer correct is option A, because the num_str is transformated into a float and added to 5. 15.0 + 5 = 20.0
English
0
0
0
86
Christian
Christian@Drackert17·
@PythonPr Nimm das BASIC vom Commodore 64. 10 N$ = "15" 20 PRINT VAL(N$) + 5 20 Und nicht wie bei Python 20.0
Deutsch
0
0
0
62
Dalo
Dalo@_theboringkid·
@PythonPr 20.0 Converts str to float Adds float to integer Python is chill like that
English
0
0
0
138
Dane
Dane@Naabe_Cherish·
@PythonPr Answer is A. 20.0
Accra, Ghana 🇬🇭 English
0
0
1
55
Paylaş