Lesson 1 ❮ Lesson List ❮ Top Page
❯ 1.1 Variables
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 7m 33s
☷ Interactive readings 5m
Let's try out Python for the first time by pressing the ► button on top of the code. This code print (show in the output) the phrase "Hello World".
Try to change it into Hello Python, run it and see if the output changes.
Now, let's try using a variable. In this code, we've added a variable called name. The value of this variable is Andy. The print command print the value of the variable name.
You can simply use the = sign to change the value of a variable. Here, we try to change the value of the variable text.
To write comment in Python, you can use the hashtag mark #. Anything after that, until the end of line, will become a comment.
Comments will not affect the program.
There are few rules of naming variables and without following these rules, some will cause errors. (Others just help you write code that's easier to read and understand).
(Note: This program has no output)
Let's look at an error you're likely to make and learn how to fix it.
The error message shows that the error starts at line 2.
The output at last line shows that the error is of the type NameError. This is further explained, which says that name 'ages' is not defined.
Now, deleting the extra s from ages will resolve this error.