List and Dictionaries in Python

List and Dictionaries in Python

 

List and Dictionaries in Python, in this article i will show you how to use list and Dictionaries in Python.

List in Python

  1. List in Python , is a list of  items reside inside a list , it can be  a Mix of String , int  etc

 

athislist=["apple", "pearl", "orange", "lemon"]

Append an Item into the List

 athislist.append("google")  

Calling the Output

>>> print(athislist)                                          
['apple', 'pearl', 'orange', 'lemon', 'google']         

Retrieving Item by range

>>> athislist[0:2]                                            
['apple', 'pearl']    

Retrieving Item from behind

>>> athislist[-1]
'lemon'      

Dictionaries in Python

  1. Dctionary is use to store groups of data
  2. The Group of Data inside the Dictionary are divided into keys and Values

Setting Up a Dictionaries

>>> userData = { "John":12345 ,"Brian" : 45678 , "Clive" :9999}

  • For Exomple : John is the keys and 12345 is the Value

Check out the item value in the dictionaries

>>> userData["John"]
12345   

Check out all item key value in the dictionaries using the .key() function

>>> userData.keys()
dict_keys(['John', 'Brian', 'Clive'])            

Check out all item value in the dictionaries using the .values() function

>>> userData.values()
dict_values([12345, 45678, 9999])     

check out Bash Scripting in Python here

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − fourteen =