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
88
22
520
88.7K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: C) Error The trap: Both are STRINGS! › a = '9' (string, not number) › b = '4' (string, not number) › String * String = TypeError! For beginners: String * int works ('9'*4='9999'), but string * string doesn't.
English
0
0
63
9.9K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr The correct answer is C) Error. Why is it an error? In Python, the * operator is overloaded, meaning it does different things depending on the data types: Number * Number: Standard multiplication (e.g., 9 * 4 = 36). String * Integer: String repetition (e.g., '9' * 4 = '9999').
English
1
1
17
2.1K
Jenny
Jenny@JennyTheDev·
@PythonPr C) Error '9' * '4' = TypeError String * String = Python says no. String * Int = Python says "9999" (if it was '9' * 4) The trick: multiplication needs at least one integer.
English
1
0
18
7.7K
Ranjan
Ranjan@Ranjanrgdev·
@PythonPr C Because we can't multiply strings but we can add them
English
1
0
5
6.2K
Jay
Jay@learnaiwthme·
@PythonPr C) Error Because a and b are both strings. In Python, string multiplication only works with an integer, not another string ('g' * 4 works, 'g' * '4' does not).
English
0
0
4
4.2K
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output: C) Error Why: In Python, string multiplication works only with an integer (e.g., 'g' * 4). Here, b = '4' is a string, so a * b raises a TypeError (can't multiply sequence by non-int).
English
0
0
3
4.5K
Siddartha DevOps
Siddartha DevOps@SiddarthaDevops·
@PythonPr a and b are string... when you write '9" * '4', python sees: left and right side sequence (string). It expects the right side to be an int. since it is noy, python riases error
English
0
0
3
4.1K
clovis
clovis@cloclodma·
@PythonPr This is an error. ‘a’ and ´b’ are strings. We cannot multiply strings
English
0
0
2
1K
The root of infinity
The root of infinity@parth_hirpara05·
Answer: D) 9999 In Python, multiplying a string by an integer (in this case, the string '9' by the string '4', which Python implicitly converts to the integer 4 for this operation) results in the string being repeated that number of times. Therefore, '9' multiplied by 4 equals '9999'
English
0
0
1
40
Evil_Hunter
Evil_Hunter@imsmartVik·
@PythonPr error bcoz string string cant be multiplied 😁 TypeError: cant multiply sequence by non-int of type str
English
0
0
1
328
Ehshanulla
Ehshanulla@Ehshanulla·
@PythonPr a is a string b is also a string Python does not allow multiplying a string by another string string * int → string repetition string * string → TypeError so output=TypeError
English
0
0
1
327
CasBlog
CasBlog@CasBlog58512·
@PythonPr C. Error. You cannot multiply strings
English
0
0
0
15
Joseph Nwachukwu
Joseph Nwachukwu@jmnwachukwu·
@PythonPr C) Error '9' and '4' are of type (string) and python needs at least one integer(e.g 4) for multiplication to work.
English
0
0
0
599
شیئر