How to access List elements

前端 未结 5 733
面向向阳花
面向向阳花 2020-11-27 19:30

I have a list

list = [[\'vegas\',\'London\'],[\'US\',\'UK\']]

How to access each element of this list?

5条回答
  •  离开以前
    2020-11-27 20:06

    Learn python the hard way ex 34

    try this

    animals = ['bear' , 'python' , 'peacock', 'kangaroo' , 'whale' , 'platypus']
    
    # print "The first (1st) animal is at 0 and is a bear." 
    
    for i in range(len(animals)):
        print "The %d animal is at %d and is a %s" % (i+1 ,i, animals[i])
    
    # "The animal at 0 is the 1st animal and is a bear."
    
    for i in range(len(animals)):
        print "The animal at %d is the %d and is a %s " % (i, i+1, animals[i])
    

提交回复
热议问题