From the course: Python for Students

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Creating variables

Creating variables - Python Tutorial

From the course: Python for Students

Creating variables

- [Instructor] A big part of programming is efficiency. Programmers are known for being lazy and we don't like to do the same thing twice. We especially don't like to do things when we could have our computer do it for us. This is where variables come in. Think of variables like a box. We can put a label on that box to tell us what is inside of it, and we can switch out the contents of the box if we want. So I want to show you how this works. In this example, I have printed some information about my dog. Notice how the word Benny appears twice. What if I wanted to change this to a different dog's name? I would need to change the word Benny in two different places. In this particular example, that's not a huge deal, but you can imagine that if we had a program that was hundreds of lines long or spanned multiple files, it could be pretty error prone to try to find and replace that word across multiple files. Instead, let's use a variable. I'm going to use a variable called dog_name and…

Contents