Differences and commonalities between dict, list, and tuple types

What is dict type, list type, tuple type?

Add an element

a={"apple":1,"orange":2,"book":3}
a["ball"]=4 #Add an element
print(a)

Execution result


a={"apple":1,"orange":2,"book":3,"ball":4}
a=["apple","orange","book"]
a.append("ball") #Add an element
print(a) 

Execution result


a=["apple","orange","book","ball"]

Delete the element

The deletion method is the same for dict type and list type. The tuple type cannot delete an element. The following two are typical ones.

dict type


a={"apple":1,"orange":2,"book":3}
a.pop("apple")
print(a)

Execution result


a={"orange":2,"book":3}

list type


a=["apple","orange","book"]
a.pop("0")
print(a)

Execution result


["orange","book"]

dict type


a={"apple":1,"orange":2,"book":3}
del a["apple"]
print(a)

Execution result


{"orange":2,"book":3}

list type


a=["apple","orange","book"]
del a[0]
print(a)

Execution result


["orange","book"]

Recommended Posts

Differences and commonalities between dict, list, and tuple types
[Python Iroha] Difference between List and Tuple
Differences between Windows and Linux directories
Difference between list () and [] in Python
Differences between yum commands and APT commands
Differences between symbolic links and hard links
Differences between Python, stftime and strptime
Differences between Ruby and Python in scope
Python> empty XXX (XXX: dict, list, tuple, set)> {} / [] / () / set ()
Differences in syntax between Python and Java
Difference between append and + = in Python list
Matplotlib Basics / Differences between fig and axes
Differences between Numpy 1D array [x] and 2D array [x, 1]
Differences in multithreading between Python and Jython
Differences between Django's request.POST ['hoge'] and request.POST.get ('hoge')
Differences between Ruby and Python (basic syntax)
Difference between numpy.ndarray and list (dimension, size)
Differences between queryStringParameters and multiValueQueryStringParameters in AWS Lambda
Summary of the differences between PHP and Python
Differences between glibc, musl libc and go resolvers
List type, tuple type 2
Differences in behavior between append () and "+ =" operators when adding data to a list in Python
List type, tuple type
list and numpy
[Python] How to sort dict in list and instance in list
EP 3 Know the Differences Between bytes, str, and unicode
Differences between numpy and pandas methods for finding variance