Tutorialslot.com

youtube facebook twitter gmail pinterest

For loop In Python

It has the ability to iterate over the items of any sequence, such as a list or a string.

Syntax:
for iterating_variable in sequence:
  statement(s)
If a sequence contains an expression list, it is evaluated first. Then, the first item in the sequence is assigned to the iterating variable iterating_var. Next, the statements block is executed. Each item in the list is assigned toiterating_var, and the statement(s) block is executed until the entire sequence is exhausted.

Example:
for letters in 'Forloop':   # Example1
  print 'Current Letter :', letters
python = ['forloop', 'while', 'if']
for temp in python:   # Example2
  print 'Current fruit :', temp
print "Good bye!"



Advertisement Powered By Google Adsense






IF YOU LIKE THIS TUTORIALS PLEASE SHARE

Share on whatsapp

POPULAR TAGS

python python tutorial learn python learning python python code learning java python language python documentation python tutor python basics python download python online python for dummies how to learn python