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
56
13
173
27.9K
Coding Computing Coach
Coding Computing Coach@CodingComputing·
@PythonPr Answer: D 9999 Solution: Observe that '9' is a string, not an int. b is an int 4. So, a * b is a multiplication of string and int. Sounds strange, but this is just repetition of the string. So, '9' * 4 is the string '9' repeated 4 times, ie, 9999 that's what gets printed.
English
0
0
11
1.4K
Pablo | Dev
Pablo | Dev@pababalle·
@PythonPr This one always catches people. "9" isn’t a number, it’s a string. Strings × ints = repetition → 9999.
English
1
1
8
2.1K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr (d) 9999 In Python, when the multiplication operator (*) is used with a string (a = '9') and an integer (b = 4), it performs string repetition, not mathematical multiplication. The original string is repeated the number of times specified by the integer. Why!?
English
1
0
2
1.1K
Sento🫡
Sento🫡@SentoMarcus·
@PythonPr C - error - you can’t multiply a string to an integer directly
English
0
0
2
461
NovayaZemlya
NovayaZemlya@ZemlyaNova27479·
@PythonPr a * 4 = a + a + a + a = '9' + '9' + '9' + '9' = '9999' print(a * 4) = print('9999') Answer: 9999
English
0
0
2
1K
Usama Mohsin
Usama Mohsin@iUsamaMohsin·
@PythonPr "9999" a is a string, not a number. So Python doesn’t do math here. It does what it always does with strings and integers. '9' * 4 means “repeat the string '9' four times,” not “multiply like an adult. You asked Python for arithmetic, and it said, “Best I can do is copy-paste.”
English
0
0
1
80
Smart💡
Smart💡@capt_ivo·
@PythonPr I'm surprised no one chose 36 🤣😂. That probably would be the first instinct for some
English
0
0
0
1.1K
juliane neema
juliane neema@JulianeN65228·
@PythonPr Output is C because you can't concatenate a string with integer
English
0
0
0
2
Palak sharma
Palak sharma@Palakshar27·
@PythonPr While adding a string and an integer (+) causes an error, multiplying a string by an integer is a perfectly valid operation, so correct answer is D as here the string 9 gets repeated 4 times and becomes 9999
English
0
0
0
8
littleDEV
littleDEV@LittleDev_X·
@PythonPr 9999 multiplying a string by an integer
English
0
0
0
11
Paylaş