[BangPypers] Beginner Help
ram sagar
rammy.sagar at gmail.com
Fri Apr 5 11:40:23 CEST 2013
Hi,
words = ['cat', 'window', 'defenestrate']
here words is a list and each element in that list can be accessed via
index.
words[0] will give cat
words[1] will give window
for more information on list :
http://docs.python.org/2/tutorial/introduction.html#lists
also in python for loop is quite from different from other programming
languages.
for more information on for loop :
http://docs.python.org/2/tutorial/controlflow.html#for-statements
for w in words:
for the first loop ,the value in words[0] is picked and assigned to w
, i.e w = words[0]
for the second loop ,the value in words[1] is picked and assigned to w ,
i.e w = words[1]
.....so on
It is always better to have understanding of what data type we are working
on and then what are the operation we are performing.
I hope that you are clear about working of for loop.
Regards
Ram Sagar Mourya
On Tue, Apr 2, 2013 at 2:38 PM, Gaurav Malhotra <gaurav.tula at gmail.com>wrote:
> Hi everyone,
>
> Below is the code (with output) which can be found in the Python Official
> Documentation:
>
> >>> # Measure some strings:
>
> ... words = ['cat', 'window', 'defenestrate']
>
> >>> for w in words:
>
> ... print w, len(w)
>
> ...
>
> cat 3
>
> window 6
>
> defenestrate 12
>
> # The Problem is:
> When "w" is not defined how python interpreter can evaluate the output??
>
> Please Explain the lines where "w" is occurred. if i would replace "w" with
> any other variable, it will show the same output.
>
> I want to know "What is happening in the back (i mean how interpreter is
> handling it)" ??
>
> Thanks & Regards,
> Gaurav Malhotra
>
> --
> *Regards
> Gaurav Malhotra
> +91-9410562301*
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
More information about the BangPypers
mailing list