Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 1 : ababccc / ababccc

Advertisement

Detailed Solution

सही उत्तर ababccc / ababccc है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Python code? `print("ab" * 2 + "c" * 3)` / निम्नलिखित Python कोड का आउटपुट क्या होगा? `print("ab" * 2 + "c" * 3)`

1.
ababccc / ababccc
2.
abcc / abcc
3.
abcabc / abcabc
4.
Error — cannot mix * and + on strings / त्रुटि — string पर * और + मिलाए नहीं जा सकते

Correct Answer: ababccc / ababccc

`*` (repetition) binds tighter than `+` (concatenation): "ab"*2 = "abab" and "c"*3 = "ccc", concatenated to "ababccc". The trap is mis-grouping as "ab" * (2 + "c") or similar. / `*` (repetition) `+` (concatenation) से कसकर बँधता है: "ab"*2 = "abab" और "c"*3 = "ccc", जुड़कर "ababccc"। जाल इसे "ab" * (2 + "c") जैसा गलत समूहित करना है।

Downloaded from PrepSnap (prepsnap.in)