python operations dictionary

The operation of the dictionary

# Simple dictionary 
alien_0 = { ' Color ' : ' Green ' , ' Point ' :. 5 }
 Print (alien_0 [ ' Color ' ])
 Print (alien_0 [ ' Point ' ])
 # Add pair 
alien_0 [ ' x_position ' ] = 0 
alien_0 [ ' y_position ' ] = 25
 Print (alien_0)
 # position of a moving at different speeds to track alien 
alien_0 = { ' x_position ': 0, ' y_position ' : 25, ' Speed ' : ' Medium ' } 
alien_0 [ ' Speed ' ] = ' FAST ' 
IF alien_0 [ ' Speed ' ] == ' SLOW ' : 
    x_increment =. 1
 elif alien_0 [ ' Speed ' ] == ' Medium ' : 
    x_increment = 2
 the else :
     #   this speed must quickly alien
    =. 3 x_increment #   new position equals the old position plus the incremental 
alien_0 [ ' x_position ' ] + = x_increment
 Print (STR (alien_0 [ ' x_position ' ]))

 

Guess you like

Origin www.cnblogs.com/hainabaichuan/p/11795610.html