Return to Home Page
      Blog     Consulting     Seminars     Calendar     Books     CD-ROMS     Newsletter     About     FAQ      Search
 

I know this is not at all central to your book, but perhaps a one-line example here would be useful. Something like:

E.g., "

for i in range(10):
" would be the equivalent of the Java expression "
for (int i = 0; i I know this is not at all central to your book, but perhaps a one-line example here would be useful.  Something like:

E.g., "

for i in range(10):
" would be the equivalent of the Java expression "
for (int i = 0; i 
f  e  x


Well that didn't come out well...

Example again:

for i in range(10):
# doSomething

equivalent to

for (int i = 0; i Well that didn't come out well...

Example again:

for i in range(10):
# doSomething

equivalent to

for (int i = 0; i

f  e  x


Okay, it's not me. It's the formatter. You know what I mean, right?

f  e  x


I'm a Python newbie but do know that for very large loops, xrange() rather than range() is your friend, so maybe you might want to change the reference from "range()" to "range() or xrange()".

f  e  x


I agree. A simple example of range() would be useful here.

f  e  x


Strictly speaking, the C for statement doesn't require a numeric iteration, and so is much more powerful than using a range. For example


for (node=head; node != NULL; node=node->next)...

Of course, given that this feature of C is most often used for iterating through a list, which Python does directly, perhaps this isn't a significant complaint.

f  e  x


With the advent of "iterator" in Python 2.2 the preceding example in C is expressed clearer in Python: the


for node in iterable:
    pass # some statements

is equivalent to:


_temp_iter = iter(c)
while True:
    try: x = _temp_iter.next()
    except StopIteration: break
    pass # some statements
f  e  x


enumerate could be mentioned

f  e  x



Add your comment below. Use an empty line between each paragraph. Paragraphs will be automatically formatted, and single carriage returns will be respected. Use <code> to begin a code block, and </code> to end a code block. Your email address will not be visible to spam harvesters or used in any way except to contact you with further questions.

Your Email Address:

Search     Home     WebLog     Consulting     Seminars     Calendar     Books     CD-ROMS     Newsletter     About     Contact     Site Design     Server Maintenance     Powered by Zope
©2007 MindView, Inc.