[Tutor] Variables (with lists??)

delegbede at dudupay.com delegbede at dudupay.com
Wed Nov 23 07:14:58 CET 2011


Hi Chris,

Straight to the point, this is how to populate a python dictionary. 

customer = {}

This statement makes a new dictionary, which is empty though, called customer. 
A python dictionary has a pair of key and value linked with semicolon and seperated from other pairs by a comma. 

 
print “Add a new customer to the database\n”

custNum = raw_input(‘Enter a customer number: ‘) 

This expects an input from the user and then sets that to the variable custName. 
Here is a thing to note here, whatever the user enters is treated as a string because of raw_input. That's another lesson as a whole. 
What's in the parenthesis would be shown at the prompt when the program is run. It tells the user what to do. 

customer['firstName'] = raw_input(‘Customer First Name: ‘)

This creates a pair of key value in a dictionary. Initially, the dictionary customer was empty. This statement now creates a key 'firstname' that has the value of whatever is entered by the user as the Customer First Name. 

customer['lastName'] = raw_input(‘Customer Last Name: ‘)

The same explanation for the above explains this and the rest all through the

customer['zip'] = raw_input(‘Customer Zip Code: ‘)

You can also look at what others would say. 

While searching google, search, creating python dictionary. 

HTH. 

Regards. 
Sent from my BlackBerry wireless device from MTN

-----Original Message-----
From: Chris Kavanagh <ckava1 at msn.com>
Sender: tutor-bounces+delegbede=dudupay.com at python.org
Date: Tue, 22 Nov 2011 23:15:49 
To: <tutor at python.org>
Subject: [Tutor] Variables (with lists??)

I was going over one of Derek Banas' tutorials on youtube, and came 
across something I hadn't seen before. A variable with a list beside it 
(see code below). He sets the variable, customer , equal to a dict. Then 
uses the variable with ['firstname'],['lastname'], ect. I've never seen 
this in my short programming life. What is this called? And is there any 
documentation on it?? I tried to google it, but had no idea what to 
google, lol. The code below is just partial code. . .

Thanks for the help, and I hope everyone has a happy Thanksgiving!




customer = {}

print “Add a new customer to the database\n”

custNum = raw_input(‘Enter a customer number: ‘)
customer['firstName'] = raw_input(‘Customer First Name: ‘)
customer['lastName'] = raw_input(‘Customer Last Name: ‘)
customer['streetAdd'] = raw_input(‘Customer Street Address: ‘)
customer['city'] = raw_input(‘Customer City: ‘)
customer['state'] = raw_input(‘Customer State: ‘)
customer['zip'] = raw_input(‘Customer Zip Code: ‘)
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list