Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   why not? (http://www.velocityreviews.com/forums/t956750-why-not.html)

Steven D'Aprano 01-21-2013 11:37 AM

Re: why not?
 
On Mon, 21 Jan 2013 11:02:10 -0600, kwakukwatiah wrote:

> f = open(r'c:\text\somefile.txt')
> for i in range(3):
> print str(i) + ': ' + f.readline(),
>
> please with the print str(i) + ‘: ‘ + f.readline(),
> why not print str(i) + f.readline(),



Because the output will be different. The first code will print:

0: first line
1: second line
2: third line


The second code will print:

0first line
1second line
2third line


You should really try these things and see what they do before asking.


--
Steven

kwakukwatiah@gmail.com 01-21-2013 05:02 PM

why not?
 
f = open(r'c:\text\somefile.txt')
for i in range(3):
print str(i) + ': ' + f.readline(),
please with the print str(i) + ‘: ‘ + f.readline(), why not print str(i) + f.readline(),


All times are GMT. The time now is 05:27 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57