csaccept.com is a computer awareness website dedicated to providing reliable and easy-to-understand information about computer technology and digital safety. The website focuses on educating students, beginners, and general users about computer basics, cyber security, emerging technologies, and practical IT skills. Through informative articles, quizzes, and real-life examples, csaccept.com aims to increase digital literacy and help users stay safe and confident in today’s technology-driven world.
Facebook ………………..
Instagram ……………..
Twitter ( X ) ……………..
YouTube
List, Dictionary, Set, Tuple and Type Conversion in Python
1. List :
Introduction
In Python, a list is a versatile and commonly used data structure that allows you to store multiple items in a single variable. Lists can hold elements of different data types such as integers, strings, floats, or even other lists.
Lists are defined by enclosing elements within square brackets [ ] and separating them with commas.
Key Features of List
- Lists are ordered collections, meaning each element has a fixed position (index).
- Indexing starts from 0.
- Lists are mutable, which means you can change, add, or remove elements after the list is created.
- Lists can store duplicate values.
List Declaration
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "orange", "grape"]
Explanation
- The
numberslist contains integer values. - The
fruitslist contains string values. - You can access elements using their index:
print(numbers[0]) # Output: 1
print(fruits[1]) # Output: banana
Common List Operations
numbers.append(6) # Add element
numbers.remove(3) # Remove element
numbers[0] = 10 # Modify element
2. Dictionary :
Introduction
A dictionary in Python is a collection of key–value pairs. It is used to store data values in a structured form, where each value is associated with a unique key.
Dictionaries are enclosed in curly braces { }.
Key Features of Dictionary
- Stores data as key : value pairs.
- Keys must be unique.
- Dictionaries are mutable.
- Provides fast access to values using keys.
- Useful for data mapping and structured data storage.
Dictionary Declaration
# Author : Codewithcurious.com
student = {
"name": "John Doe",
"age": 20,
"major": "Computer Science"
}
Accessing Dictionary Values
print(student["name"]) # Output: John Doe
print(student["age"]) # Output: 20
Updating Dictionary
student["age"] = 21
student["city"] = "Delhi"
3. Set :
Introduction
A set in Python is a collection of unique elements. It is mainly used when duplicate values are not allowed.
Sets are enclosed in curly braces { }, similar to dictionaries, but without key-value pairs.
Key Features of Set
- Stores unique values only.
- Sets are unordered.
- Does not support indexing.
- Sets are mutable.
- Supports mathematical operations like union, intersection, and difference.
Set Example
numbers = {1, 2, 3, 4, 5}
Set Operations
numbers.add(6)
numbers.remove(2)
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.union(set2)) # {1, 2, 3, 4, 5}
print(set1.intersection(set2)) # {3}
4. Tuple :
Introduction
A tuple in Python is an immutable ordered collection of elements enclosed in parentheses ( ).
Tuples are used when data should not be modified after creation.
Key Features of Tuple
- Tuples are ordered.
- Tuples are immutable (cannot be changed).
- Supports indexing and unpacking.
- More memory-efficient than lists.
- Used when data integrity is important.
Tuple Declaration
# Author : Codewithcurious.com
student = ("John Doe", 20, "Computer Science")
Explanation
The tuple student contains:
- Name → “John Doe”
- Age → 20
- Field → “Computer Science”
Accessing Tuple Elements
print(student[0]) # Output: John Doe
print(student[1]) # Output: 20
5. Type Conversion (Type Casting) :
Introduction
Type conversion, also known as type casting, is the process of converting one data type into another.
Python provides several built-in functions for type conversion.
Common Type Casting Functions
int()– Converts a value to an integerfloat()– Converts a value to a floatstr()– Converts a value to a stringlist()– Converts a value to a listtuple()– Converts a value to a tuplebool()– Converts a value to a boolean
Type casting is very useful when performing operations or comparisons between different data types.
Type Conversion Example
# Author : CodewithCurious.com
# Integer to String
num = 10
num_str = str(num)
print("Number as a string:", num_str)
# String to Integer
num_str = "20"
num = int(num_str)
print("Number as an integer:", num)
# Float to Integer
num_float = 3.14
num_int = int(num_float)
print("Float as an integer:", num_int)
Output
Number as a string : 10
Number as an integer : 20
Float as an integer : 3
Conclusion :
- List → Ordered & mutable
- Dictionary → Key-value structured data
- Set → Unique & unordered elements
- Tuple → Ordered & immutable data
- Type Conversion → Changing data types for flexibility
Viva Questions – Short Answers :
1. What is a list in Python?
A list is an ordered, mutable collection used to store multiple items in a single variable.
2. Is list mutable or immutable?
A list is mutable.
3. What is indexing?
Indexing is a way to access elements of a sequence using their position number, starting from 0.
4. Difference between list and tuple.
A list is mutable, while a tuple is immutable.
5. What is a dictionary?
A dictionary is a collection of key–value pairs used to store structured data.
6. Why keys must be unique in dictionary?
Keys must be unique to correctly identify and access values without confusion.
7. How do you access dictionary values?
Dictionary values are accessed using their keys.
8. What is a set?
A set is an unordered collection of unique elements.
9. Why sets do not allow duplicates?
Sets automatically remove duplicate values to maintain uniqueness.
10. Are sets ordered or unordered?
Sets are unordered.
11. What is a tuple?
A tuple is an ordered, immutable collection of elements.
12. Why tuples are immutable?
Tuples are immutable to ensure data integrity and improve performance.
13. What is type conversion?
Type conversion is the process of changing one data type into another.
14. Difference between int() and float().int() converts values to integer, while float() converts values to decimal form.
15. What happens when float is converted to int?
The decimal part is removed.
16. What is bool() function?
The bool() function converts a value into a boolean (True or False).
17. Output of bool(0)?
The output is False.
18. Can list contain mixed data types?
Yes, a list can contain different data types.
19. Which data structure is fastest?
Tuple is generally faster than list.
20. Where are tuples commonly used?
Tuples are used where data should not be changed, such as fixed records.
Python MCQs (50 Questions)
(List, Dictionary, Set, Tuple & Type Conversion)
List (MCQs 1–12)
1. Which data structure is mutable in Python?
A. Tuple
B. String
C. List
D. Integer
✅ Answer: C
2. Lists in Python are enclosed within:
A. ( )
B. { }
C. [ ]
D. < >
✅ Answer: C
3. Indexing in a Python list starts from:
A. 1
B. -1
C. 0
D. Any number
✅ Answer: C
4. Which method is used to add an element at the end of a list?
A. add()
B. append()
C. insert()
D. extend()
✅ Answer: B
5. What will be the output of len([1,2,3])?
A. 2
B. 3
C. 1
D. Error
✅ Answer: B
6. Which of the following allows duplicate values?
A. Set
B. Dictionary
C. Tuple
D. List
✅ Answer: D
7. How do you remove an element from a list?
A. delete()
B. remove()
C. poplist()
D. erase()
✅ Answer: B
8. Which statement is true about lists?
A. Immutable
B. Ordered
C. Unchangeable
D. Fixed size
✅ Answer: B
9. Which function converts a value into a list?
A. list()
B. tuple()
C. set()
D. dict()
✅ Answer: A
10. What is the output of [1,2,3][1]?
A. 1
B. 2
C. 3
D. Error
✅ Answer: B
11. Which list method removes the last element?
A. pop()
B. remove()
C. delete()
D. cut()
✅ Answer: A
12. Can a list contain different data types?
A. Yes
B. No
C. Sometimes
D. Error
✅ Answer: A
Dictionary (MCQs 13–22)
13. A dictionary stores data in the form of:
A. Values only
B. Keys only
C. Key-value pairs
D. Index-value
✅ Answer: C
14. Dictionary keys must be:
A. Mutable
B. Duplicate
C. Unique
D. List
✅ Answer: C
15. Dictionaries are enclosed in:
A. ( )
B. [ ]
C. { }
D. < >
✅ Answer: C
16. How do you access a value in a dictionary?
A. Using index
B. Using key
C. Using value
D. Using loop only
✅ Answer: B
17. Which of the following is mutable?
A. Tuple
B. Dictionary
C. String
D. Integer
✅ Answer: B
18. Which method is used to get all keys?
A. keys()
B. values()
C. items()
D. get()
✅ Answer: A
19. What happens if you use a duplicate key?
A. Error
B. Program stops
C. Old value replaced
D. Both stored
✅ Answer: C
20. Which function converts data into a dictionary?
A. dict()
B. list()
C. tuple()
D. set()
✅ Answer: A
21. Dictionary elements are accessed by:
A. Position
B. Index
C. Key
D. Order
✅ Answer: C
22. Dictionary is best suited for:
A. Mathematical operations
B. Storing unique values
C. Structured data
D. Index-based access
✅ Answer: C
Set (MCQs 23–32)
23. A set contains:
A. Duplicate values
B. Unique values
C. Ordered values
D. Indexed values
✅ Answer: B
24. Sets are:
A. Ordered
B. Indexed
C. Unordered
D. Immutable
✅ Answer: C
25. Which symbol is used for set?
A. [ ]
B. ( )
C. { }
D. < >
✅ Answer: C
26. Can we access set elements using index?
A. Yes
B. No
C. Sometimes
D. Depends
✅ Answer: B
27. Which operation finds common elements?
A. Union
B. Difference
C. Intersection
D. Merge
✅ Answer: C
28. Which method adds an element to a set?
A. append()
B. add()
C. insert()
D. push()
✅ Answer: B
29. Which data structure removes duplicates automatically?
A. List
B. Tuple
C. Set
D. Dictionary
✅ Answer: C
30. Sets support which type of operations?
A. Arithmetic
B. Logical
C. Mathematical
D. Bitwise
✅ Answer: C
31. Set elements must be:
A. Mutable
B. Immutable
C. Indexed
D. Ordered
✅ Answer: B
32. Which function converts data into a set?
A. list()
B. tuple()
C. set()
D. dict()
✅ Answer: C
Tuple & Type Conversion (MCQs 33–50)
33. Tuple is enclosed in:
A. [ ]
B. { }
C. ( )
D. < >
✅ Answer: C
34. Tuples are:
A. Mutable
B. Immutable
C. Changeable
D. Flexible
✅ Answer: B
35. Which is faster than list?
A. Set
B. Dictionary
C. Tuple
D. String
✅ Answer: C
36. Tuples are used when:
A. Data must change
B. Data should not change
C. Large data
D. Indexing is not required
✅ Answer: B
37. Which function converts value into tuple?
A. list()
B. tuple()
C. set()
D. dict()
✅ Answer: B
38. Type conversion is also called:
A. Type checking
B. Type testing
C. Type casting
D. Type matching
✅ Answer: C
39. Which function converts string to integer?
A. str()
B. int()
C. float()
D. bool()
✅ Answer: B
40. int(3.7) returns:
A. 3
B. 4
C. 3.7
D. Error
✅ Answer: A
41. Which converts value to boolean?
A. bool()
B. int()
C. str()
D. list()
✅ Answer: A
42. Output of bool(0) is:
A. True
B. False
C. 0
D. Error
✅ Answer: B
43. Output of bool(5) is:
A. False
B. 0
C. True
D. Error
✅ Answer: C
44. Which function converts value to string?
A. int()
B. float()
C. str()
D. list()
✅ Answer: C
45. Type casting is useful for:
A. Looping
B. Comparison
C. Data conversion
D. All of the above
✅ Answer: D
46. Which conversion may cause data loss?
A. int to str
B. float to int
C. list to tuple
D. str to list
✅ Answer: B
47. Which is immutable?
A. List
B. Set
C. Dictionary
D. Tuple
✅ Answer: D
48. Can tuples contain different data types?
A. Yes
B. No
C. Sometimes
D. Error
✅ Answer: A
49. Which is memory efficient?
A. List
B. Tuple
C. Set
D. Dictionary
✅ Answer: B
50. Type conversion functions are:
A. User-defined
B. Built-in
C. External
D. Invalid
✅ Answer: B
https://csaccept.com/variables-identifier-data-types-keywords-operators/

