Python entry statement of if statement while statement for statement

  • 2020-04-02 14:32:08
  • OfStack

Python entry statement, including if statement, while statement, for statement, for python beginners reference.


//Example if statement
name = 'peirong';

if name == 'peirong':
 print 'this is peirong';
elif name== 'maojun':
 print 'this is maojun';
else:
 print 'others';

//While statement
i = 0;
a = range(10);
while i < a.__len__():
 print i;
 i = i+1;

//For statement
a = range(1,10);
for i in a:
 print i;
else:
 print 'The for loop is over!'

//The continue statement
a = range(1000)
for i in a:
  if i % 3 == 0:
    print 'chuyi 3 yu 0 ';
  elif i % 3 == 1:
    print 'chuyi 3 yu 1 ';
  else:
    continue


Related articles: