mardi 7 juillet 2015

Pass Statement- python

I quite new to python programing and try to understand, in this code, why python print the letter "w"? (i work with python 2.7.8):

 LetterNum = 1

for Letter in 'Howdy!':
    if Letter == 'w':
        pass
        print 'Encountered w, not processed.'
    print ('Letter', LetterNum, 'is', Letter)
    LetterNum+= 1

i get this result:

>>> 
('Letter', 1, 'is', 'H')
('Letter', 2, 'is', 'o')
Encountered w, not processed.
('Letter', 3, 'is', 'w')
('Letter', 4, 'is', 'd')
('Letter', 5, 'is', 'y')
('Letter', 6, 'is', '!')

while i thought i get this result:

>>> 
('Letter', 1, 'is', 'H')
('Letter', 2, 'is', 'o')
Encountered w, not processed.
('Letter', 4, 'is', 'd')
('Letter', 5, 'is', 'y')
('Letter', 6, 'is', '!')
>>>  

Aucun commentaire:

Enregistrer un commentaire