Code -
num1 = [10, 20]
num2 = [30]
num1.append(num2)
print(num1)
Solution and Explanation :
The above code appends the list num2 as a single element to the list num1. So, num1 becomes a nested list. Here's the breakdown of the code:
num1 = [10, 20]
num2 = [30]
num1.append(num2)
print(num1)
num1 is initially [10, 20].
num2 is [30].
num1.append(num2) appends num2 as a single element to num1, resulting in num1 becoming [10, 20, [30]].
print(num1) prints the updated num1.
The output of the code will be: [10, 20, [30]]
0 Comments:
Post a Comment