Post

@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

@PythonPr This one always catches people.
"9" isn’t a number, it’s a string.
Strings × ints = repetition → 9999.
English

@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

@PythonPr a * 4 = a + a + a + a = '9' + '9' + '9' + '9' = '9999'
print(a * 4) = print('9999')
Answer: 9999
English

@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

@PythonPr String is a text not a number. So the answer will be D
English

@PythonPr Output is C because you can't concatenate a string with integer
English

@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




























