Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
- *************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet.
- ***************************************************************
IDLE 2.6 >>> print 'hello world' hello world >>> name = raw_input('What is your name?\n') # \n is a newline What is your name? print 'Hi', name >>> my_list = ['john', 'pat', 'gary', 'michael'] for i, name in enumerate(my_list):
- print "iteration %i is %s" % (i, name)
>>> def greet(name):
- print 'hello', name
greet('Jack') greet('Jill') greet('Bob') import re for test_string in ['555-1212', 'ILL-EGAL']:
- if re.match(r'^\d{3}-\d{4}$', test_string):
- print test_string, 'is a valid US local phone number'
- print test_string, 'rejected'
prices = {'apple': 0.40, 'banana': 0.50} my_purchase = {
- 'apple': 1, 'banana': 6}
grocery_bill = sum(prices[fruit] * my_purchase[fruit]
- for fruit in my_purchase)
print 'I owe the grocer $%.2f' % grocery_bill #!/usr/bin/env python # This program adds up integers in the command line import sys try:
- total = sum(int(arg) for arg in sys.argv[1:]) print 'sum =', total
except ValueError:
- print 'Please supply integer arguments'
# indent your Python code to put into an email import glob # glob supports Unix style pathname extensions python_files = glob.glob('*.py') for fn in sorted(python_files):
print '
', fn
- for line in open(fn):
- print ' ' + line.rstrip()