python - Pass statement in an if statement -


i try understand, in code, why python print letter "w"? (i work python 2.7.8):

letternum = 1  letter in 'howdy!':     if letter == 'w':         pass         print 'encountered w, not processed.'     print ('letter', letternum, 'is', letter)     letternum+= 1 

i 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 thought should result:

>>>  ('letter', 1, 'is', 'h') ('letter', 2, 'is', 'o') encountered w, not processed. ('letter', 4, 'is', 'd') ('letter', 5, 'is', 'y') ('letter', 6, 'is', '!') >>>   

you trying use pass though continue. pass nothing, while continue skips current iteration. here code want correct usage of continue:

letternum = 1  letter in 'howdy!':     if letter == 'w':         print 'encountered w, not processed.'         continue     print ('letter', letternum, 'is', letter)     letternum+= 1 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -