Updated document.txt

goromlagche authored
revision afcf3e1b8bf583a46cfc9768538ff174b4abb140
document

# **Python Essential Reference**

## Print Stuff
1. print year, principal
2. print "%3d %0.2f" % (year, principal)
3. print format(year,"3d"),format(principal,"0.2f")
4. print "{0:3d} {1:0.2f}".format(year,principal)

## File
### Read File:
f = open("foo.txt") # Returns a file object
line = f.readline() # Invokes readline() method on file
while line:
print line, # trailing ',' omits newline character
print(line,end='') # Use in Python 3
line = f.readline()
f.close()
### Write File:
1. f = open("out","w") # Open file for writing
while year <= numyears:
principal = principal * (1 + rate)
print >>f,"%3d %0.2f" % (year,principal)
year += 1
f.close(
//f.write("%3d %0.2f¶
" % (year,principal))
year += 1
f.close()
2. import sys
sys.stdout.write("Enter your name :")
name = sys.stdin.readline()
3. name = raw_input("Enter your name :"
)