How to select Python Tuple/Dictionary Values for a given Index?

PythonServer Side ProgrammingProgramming

Items in tuple are indexed. Slice operator allows item of certain index to be accessed

>>> T1=(12, "Ravi", "B.Com FY", 78.50)
>>> print (T1[2])
B.Com FY

Items in dictionary are not indexed. Value associated with a certain key is obtained by putting in square bracket. The get() method of dictionary also returns associated value.

>>> D1={"Rollno":12, "class":"B.com FY", "precentage":78.50}
>>> print (D1['class'])
B.com FY
>>> print (D1.get('class'))
B.com FY


raja
Published on 08-Feb-2018 20:02:06
Advertisements