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
39
8
86
11.3K
Código Pitón
Código Pitón@codigopiton·
El operador * está reimplementado para algunos tipos de datos en Python (gracias al método mágico __mul__). En el caso de las cadenas de texto, el comportamiento es replicar la cadena tantas veces como indique el entero por el que se multiplica. Por tanto, la solución es la B: 1010
Español
0
0
1
102
PyBerry Tech 🐍🍓
PyBerry Tech 🐍🍓@PyBerryTech·
@PythonPr Option B : 1010 a is a string, not a number. In Python, multiplying a string by an integer repeats the string. So "10" * 2 becomes "1010". The print statement outputs 1010, not 20, because no numeric multiplication occurs here.
English
0
0
1
574
와이낫 연구소
와이낫 연구소@Whynot_Labs·
@PythonPr "10" is a string, and 2 is an integer. The string "10" will be repeated twice. Answer: 1010
English
0
0
0
2
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output: B. 1010 Because a is a string ("10") and b is an int (2). In Python, string * int means repeat the string
English
0
0
8
946
CasBlog
CasBlog@CasBlog58512·
@PythonPr C, error. The a variable is a string. You cannot multiply a string with an int(number)
English
0
0
0
224
pooja_jha
pooja_jha@poojajha29·
@PythonPr Output : 1010 a = "10" means it's string b = 2 means it's integer Print ("10" * 2 ) means string repetition so "10" is written two times Output is 1010
English
0
0
1
289
guth
guth@guthleifur·
@PythonPr B, 'cause 10 is a string, multiplied by an int. As a result, we get a repeated string
English
0
0
0
15
Muhammad Yusuf
Muhammad Yusuf@quarksci·
Floats are rejected because the Sequence Protocol requires discrete indexing; partial repetition breaks UTF-8 encoding boundaries—how do you render 0.5 of a multi-byte character? Negatives are clipped to zero in the CPython source (string_repeat) to maintain Total Function semantics and avoid breaking dynamic loops. ​If we allowed 1.5x, would it be s + s[:len(s)//2]? That breaks the Algebraic Monoid properties where (s*a)*b must equal s*(a*b). Integer-only domains keep the math clean.
English
0
0
1
16
Jenny
Jenny@JennyTheDev·
@PythonPr Answer: B. 1010 Python: "You want multiplication? Best I can do is repetition" This is why we have type hints now 💀
English
0
0
0
355
Terrence
Terrence@terrenceeleven·
@PythonPr B. 1010 I would have gone with Error since you cannot multiply a string with a integer. .@PythonPr
English
0
0
0
128
xReaverenDx
xReaverenDx@RevMathiasLust·
@PythonPr Error! No quotes! I know this one 🤣😅
English
0
0
0
73
Baller_G 🌚
Baller_G 🌚@Abdulsalam65252·
@PythonPr The apostrophe turns 'a' value into a string hence the answer is error
English
0
0
0
9
Paylaş