Informatics Practices
Which of the following commands will create a list?
- List1=list ()
- List1= []
- List1=[1,2,3,"a"]
- All of these
Answer
All of these
Reason — All of the provided commands will create a list in Python:
List1=list()initializes an empty list using the list constructor.List1=[]directly initializes an empty list using square brackets.List1=[1, 2, 3, "a"]initializes a list with mixed data types including integers and a string.
Related Questions
Which of the following statements is correct about list?
- List can contain values of mixed data types.
- List can contain duplicate values.
- A list with no elements is called an empty list.
- All of these
Which operator can be used with list?
- in
- not in
- Both 1 & 2
- Arithmetic Operators only
What is the use of append() function in list?
- It adds an item to the end of the list.
- It adds an item at the beginning of the list.
- It adds an item anywhere in the list.
- All of these
Select the output of the following expression:
str1 = "pen" print(list(str1))- ['p', 'e', 'n' ]
- [pen]
- [p/e/n]
- { "pen" }