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
24
12
129
12.6K
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: A) ['a', 'b', 'c'] x += 'c' works like x.extend('c')! › += iterates through the string 'c' › Since 'c' has one character, adds 'c' to list › Result: ['a', 'b', 'c'] For beginners: Try x += 'abc' and you'd get ['a','b','a','b','c'] each char added!
English
0
0
0
347
Second Mind - Systems
Second Mind - Systems@Secondmindsys·
Answer: A — ['a', 'b', 'c'] ✅ += on a list acts like extend(), not append(). Strings are iterables, so 'c' is unpacked — one character at a time. x = ['a','b'] x += 'c' # extend # ['a','b','c'] Swap it for append('c') and the logic flips — append() adds the object, += unpacks it.
English
0
0
0
781
Premakumar Thevathasan (Prem Iyer)
Premakumar Thevathasan (Prem Iyer)@KumarT00623760·
@PythonPr Answer is ['a', 'b', 'c']. To break down the given code: x = ['a', 'b'] # Initializing a list x with two elements: 'a' and 'b' x += 'c' # Using the += operator to add 'c' to the list x print(x) # Printing the updated list x For More Reference =>>
Premakumar Thevathasan (Prem Iyer) tweet media
English
0
0
0
145
#!/usr/bin 🇮🇳
#!/usr/bin 🇮🇳@iamjogi·
@PythonPr It's definitely not B. The correct choice is not listed in the other three. How do A, C, D differ from each other?
English
0
0
0
391
Yash
Yash@buildwithyash·
@PythonPr Option A it will just append the list
English
0
0
0
416
Moises
Moises@moises_mr1·
@PythonPr correct answer is A) ['a', 'b', 'c']
English
0
0
0
46
Paylaş