Posts

Showing posts with the label List

List Quiz

Python List Quiz Python List - 15 MCQ Quiz 1. Which of the following is a valid way to create a list in Python? list = (1,2,3) list = [1,2,3] list = {1,2,3} list = 2. Lists in Python are ____. Immutable Mutable Constant Fixed 3. Which function is used to find the length of a list? count() len() size() length() 4. What is the index of the first element in a Python list? 0 1 -1 None 5. What will be the output of len([10, 20, 30, 40]) ? 3 4 5 Error 6. What method adds an element to the end of a list? append() add() insert() extend() 7. Which method removes the last element from a list? remove() delete() pop() discard() 8. What is the output of [1,2,3] + [4,5] ? [1,2,3,4,5] [5,7,8] [1,2,3][4,5] Error 9. How can you access the last element of a list named my_list ? my_list[-1] my_list[last] my_list[len] my_list[end] 10. What does my_list.clear() do? Deletes the list v...

Topic 12: What is List in python?

Data Type " List " in Python In Python, a List is one of the most commonly used and versatile data types. It allows us to store multiple items in a single variable. Lists are ordered, mutable (changeable), and allow duplicate values  making them perfect for storing collections of data such as numbers, strings , or even other lists. A List in Python is defined as a sequence of items enclosed in square brackets [ ] , separated by commas. Syntax: list_name = [item1, item2, item3, ...] Example: fruits = ["apple", "banana", "cherry"] numbers = [10, 20, 30, 40, 50] mixed = [10, "hello", 3.14, True] Characteristics of Python Lists Property Description Ordered The items have a defined order and can be accessed using an index. Mutable You can change, add, or remove items after creation. Heterogeneous A list can store elements of different data types. Allows Duplicates Lists can contain repeated elements. Dyna...