Introducing Python © Chirag Wazir 2002 Prev   Index   Next

Input/Output

print, print %, raw_input()

import math

radius = float(raw_input("Enter radius of circle: "))
print "Area =", math.pi * radius ** 2
print "Circumference =", 2 * math.pi * radius
print "The value of %s is approximately %5.3f" % ("Pi", math.pi)
Enter radius of circle: 7
Area = 153.938040026
Circumference = 43.9822971503
The value of Pi is approximately 3.142

Files:

f = open('workfile.txt', 'w')
f.write(data)
f.close()

read(), readline(), readlines()
seek(), tell()