Informatics Practices
What will be the output of the following operation?
L1 = [1,2]
L2 = [3, 4]
(L1 + L2)*2
- [2, 4, 6, 8]
- [1, 2, 3, 4, 1, 2, 3, 4]
- [1, 3, 4, 4]
- [3, 4, 1, 2]
Python List Manipulation
1 Like
Answer
[1,2,3,4,1,2,3,4]
Reason — The code initializes two lists, L1 with elements [1, 2] and L2 with elements [3, 4]. It then concatenates these two lists using the + operator, resulting in [1, 2, 3, 4]. Next, it multiplies this concatenated list by 2 using the * operator, which repeats the elements of the list. Therefore, the final output of (L1 + L2) * 2 is [1, 2, 3, 4, 1, 2, 3, 4].
Answered By
1 Like
Related Questions
Given A = "[22, 4.88, "India", "T"]" the data type of A is
- List
- String
- Dictionary
- Tuple
Find the output of the following code:
number = [1, 5, 7, 0, 4] print(number[2:3])- [5]
- [7]
- [7,0]
- None of these
Assertion (A): List in Python is a collection of values of any type.
Reasoning (R): In lists, you can change the elements of a list in place.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Consider the given two statements:
T1 = [3, 9, 0, 1, 7]
T2 = [5, 1, 0, 7, 5.5]Assertion (A): Output of
print(len(T1) == len(T2))is True.Reasoning (R): The
len()function returns the number of elements in the list. If two lists have same number of elements, then==operator will return True.- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.