Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Which of the following data types is immutable in Python?

Asked by David Edmunds Jul 15, 2024 1.1K views 1 answer
Share

About this question

Which of the following data guys is immutable in the context of Python programming language? Here are the options given below:-

  1. Lists

My_list = [1, 2, 3]

My_list.append(4)  # my_list is now [1, 2, 3, 4]

  1. Dictionaries

My_dict = {‘a’: 1, ‘b’: 2}

My_dict[‘c’] = 3  # my_dict is now {‘a’: 1, ‘b’: 2, ‘c’: 3}

  1. Sets

My_set = {1, 2, 3}

My_set.add(4)  # my_set is now {1, 2, 3, 4}

  1. Tuple

My_tuple = (1, 2, 3)

# Any attempt to modify my_tuple will result in an error

# For example: my_tuple[0] = 4 will raise a TypeError

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.