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
35
6
119
8.4K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: (A) "abcdefdef" This problem demonstrates string manipulation in Python. Explanation String Repetition: In Python, the multiplication operator (*) used with a string and an integer repeats the string that many times. So, s2 * 2 evaluates to "defdef" [1.1].
English
1
0
11
378
vamsh
vamsh@vomshiii·
@PythonPr A * has more presence then +
English
0
0
1
152
Yama_jptw
Yama_jptw@Yamajptw·
@PythonPr A) is my answer. The 3rd line code, result= s1+ s2*2 is to use the + operator to concatenate strings s1 and s2 *2. When s2 *2, the string "def" will be doubled and produce a new string "defdef". Since s1 comes first in the formula of result, print (result) is “abcdefdef”.
English
0
0
1
355
Biel Men
Biel Men@BielMenHaha·
@PythonPr Alternative A. First it multiplies "def" 2 times, generatibg a new str instance, then it concatenates as suffix if "abc"
English
0
0
1
148
Ellen Misaki
Ellen Misaki@ellenzmis·
@PythonPr A. Def (s2) make it double (*2) then combine it with abc (s1)
English
0
0
0
7
Algis
Algis@AlgisKun·
@PythonPr Answer is A but for fucks sake. Split that thing in multiple lines or at least put parenthesis on it. Youre operating strings, not integers.
English
0
0
0
11
Paylaş