Mutable Sequence Types in Python
Mutable Sequence Types in Python
Mutable Sequence Types are data structures that allow you to store and manipulate collections of items where the contents can be changed after creation. Mutable sequences can be modified by adding, removing, or modifying elements.
Mutable Sequence Types in Python
Mutable objects can be changed after their creation. Python provide some mutable sequence types :
- List
- Dictionary
- Set
Example
List
>>> companies = ['tata','wipro','accenture'] >>> companies ['tata', 'wipro', 'accenture'] >>> companies[0]='tcs' >>> companies ['tcs', 'wipro', 'accenture'] >>> companies[-1]='cognizant' >>> companies ['tcs', 'wipro', 'cognizant']
Dictionary
>>> dictionary1 = {'Prep':'Insta', 1:'Myname'} >>> dictionary1 {'Prep': 'Insta', 1: 'Myname'} >>> dictionary1['Prep']='PrepInsta' >>> dictionary1 {'Prep': 'PrepInsta', 1: 'Myname'} >>> dictionary1[0]='Prep' >>>dictionary1 {'Prep': 'PrepInsta', 1: 'Myname', 0: 'Prep'}
Set
>>> set1=set(companies) >>> set1 {'wipro', 'tcs', 'cognizant'} >>> set1.add('accenture') >>> set1 {'accenture', 'wipro', 'tcs', 'cognizant'}
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment