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
41
9
122
13.5K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: D (9999) The trap: a is a string '9', not the number 9! › '9' * 4 performs string repetition. › Result: '9999' (four 9s, not 36!) For beginners: string * int repeats the string. To get 36, use int(a) * b = 9 * 4. Quotes make it a string!
English
0
1
6
814
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: D) 9999 In Python, the multiplication operator (*) can be used with a string and an integer. When a string is multiplied by an integer, the string is concatenated (repeated) that many times. a is a string with the value '9'. b is an integer with the value 4.
English
1
0
4
375
Jenny
Jenny@JennyTheDev·
@PythonPr D) 9999 String * int repeats the string. So '9' * 4 = '9999'.
English
0
0
2
721
ANKIT 𓃱
ANKIT 𓃱@A9kitSingh·
@PythonPr Answer is D) 9999 In Python, multiplying a string by an integer repeats the string. So '9' * 4 becomes '9999'.
English
0
0
2
362
Sixtus Agbakwuru
Sixtus Agbakwuru@SixtusAgbakwuru·
The output is C. Error. Why? Python is a strongly typed language. The - operator is defined for numerical subtraction, but here, a is a string ('9') and b is an integer (4). Python does not perform implicit type conversion for arithmetic operators. Key Concepts: · Type Error: The operation str - int is undefined, so Python raises a TypeError. · Type Conversion: You would need explicit conversion, e.g., print(int(a) - b) for 5, or print(a + str(b)) for string concatenation ('94'). This is a fundamental check of understanding data types and operator semantics. At @Spraditech, we emphasize these core concepts because mastering the rules of a language prevents countless bugs and is essential for writing robust, predictable code. Follow-up: What would print(a * b) output, and why? 🧠
English
2
0
1
784
Jay
Jay@learnaiwthme·
@PythonPr D) 9999 In Python, multiplying a string by an integer repeats the string, so '9' * 4 becomes '9999'.
English
0
0
0
288
Lingeswar Reddy .C
Lingeswar Reddy .C@lingeswar_rdy·
@PythonPr D because ,A is string does not multiply with B , it prints how many times you enter B
English
0
0
0
210
Dunlow
Dunlow@DunlowCode·
@PythonPr C) Error Cannot multiply an int and a str without int(a)
English
0
0
0
2
Terrence
Terrence@terrenceeleven·
@PythonPr D) 9999 Never experimented with multiplying different types of variables. .@PythonPr
English
1
0
0
114
Paylaş