Search this site
Embedded Files
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
  • More
    • Home
    • Courses
    • Contact

日本語  ❯

Lesson 1    ❮    Lesson List    ❮    Top Page

❯  1.1  Variables

1.2 Strings

1.3 Numbers

1.4 Lists

1.5 List Methods

1.6 Slice Operator 

⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ 
EXPECTED COMPLETION TIME
❲▹❳  Video   7m 33s
☷  Interactive readings   5m

Starting Python with print

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.

Saving a value to a variable

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.

Changing the variable value

You can simply use the = sign to change the value of a variable. Here, we try to change the value of the variable text.

Writing Comments in Python

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.

WRITE BETTER CODE
Naming Variable

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)

LEARN FROM ERROR
Understanding Error Message

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.

©2023. All rights reserved.  Samy Baladram,
Graduate Program in Data Science - GSIS - Tohoku University
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse