Intro to Python3 – Hello World

Welcome back coder!!!

In this lesson we will take our first steps to programming with python.

If you have not installed python yet, please go ahead and watch our training videos on how to install.  Once you are done come back and you’ll be ready to begin.

It’s common programming practice to start of with “Hello World” when you are learning new language.  The reason is because it helps to teach you the syntax (programming style).

With that said, let’s get started.

Open your terminal or command prompt and enter the following command:

python3

This will start the python command line interpreter which will allow you to directly enter python commands without having to setup a text editor or other coding environment (we’ll get to that in advanced lessons).

python3_command.png

Now that you are in the command line interpreter for Python3 you we can begin to enter the our very first python command.

"Hello World"

This is a simple command that consists of some text without quotation marks.  When you press enter/return the same text is simple displayed on the following line.

hello_world_enter
“Hello World”, entered in command line
Okay, we’ve entered a simple command but it does doing anything interesting does it. Well luckily python comes with a set of built in commands (aka functions).  Think of functions as ingredients to a recipe, basically something that we can add to our program.

So something we can do is use a built in python command to capitalize all the letters of our string.

"Hello World".upper()

Notice the output is now all uppercase, simple but effective.

hello_world_upper.png
“Hello World”, all uppercase
Okay let’s break this down for the command we entered.

  1. First we enter the string that we wish to use for this operation, “Hello World”
  2. We then enter a period to allow us to access additional functionality.
  3. Specify the name of the command that we want to use, upper()

Okay let’s try another function.  This time we are going to count the number of times that an individual letter appears in the same string.

"Hello World".count('l')

Count letters in string
Count the number of times a letter appears in a string
Okay let’s break this down for the command we entered.

  1. First we enter the string that we wish to use for this operation, “Hello World”
  2. We then enter a period to allow us to access additional functionality for a string
  3. Specify the name of the command that we want to use, count()
  4. Inside the parenthesis for the command we the letter that we wish to lookup.  We surround that letter by quotations (single or double, doesn’t matter).

In additional lessons we’ll go much more in depth but for now pat yourself on the back, you’ve begun you first steps into the world or programming.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s