Lesson 4. Variables and expressions: giving names and values to things

 

After reading lesson 4, you’ll be able to

  • Write code that creates Python objects
  • Write code that assigns objects to variables

In your everyday life, you encounter many physical objects, or things. Each of these things has a name. They have names because it’s much easier to refer to them using a name rather than a description.

Using names is a great help when you’re always manipulating things, or objects. Some things are simple, such as the number 9. Some are more complicated, such as a dictionary. I can give the name Nana to the number 9, and the name Bill to my dictionary. You can give things (almost) any name you want. You can even give names to combinations of things. For example, if I glue a banana to my laptop cover to create a new thing, I can name that new trendy creation Banalaptop. Individual things can be named as well; if I have two apples, I can name one Allie and the other one Ollie.

After you name things, you can refer to them later without any confusion. The benefit of using names is that you don’t have to re-create (in programming, recalculate) values. When you name a thing, you inherently remember every detail about it.

4.1. Giving names to things

 
 
 

4.2. Introducing variables

 
 

Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage