Python two loops running one iteration each at a time -


i'm doing experimenting python args , kwargs , ran unexpected issue. code is:

def argsandkwargs(*args,**kwargs):     sum = 0     arg in args:         sum += arg         print(sum)     i, j in kwargs.items():         print('i ' + + ' , j ' + j)  argsandkwargs(5,2,3,6,3,7,actor='rdj',movie='iron man') 

the output is:

5 movie , j iron man actor , j rdj 7 movie , j iron man actor , j rdj 10 movie , j iron man actor , j rdj 16 movie , j iron man actor , j rdj 19 movie , j iron man actor , j rdj 26 movie , j iron man actor , j rdj 

if args , kwargs loops separate, expect see:

5 7 10 16 19 26 5 movie , j iron man actor , j rdj 

why python behaving way? looks it's running 1 iteration @ time each loop, instead of iterations each loop before moving next.

double check you're not mixing spaces , tabs. python thinks second loop indented same level print statement above it.

thank @kevin, had spaces first loops, , indents second; didn't realize python differentiated these.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -