2. Print() function

Spread the love

Let’s write our first Python program. Type print, all in lowercase, open and close parenthesis, and inside these parentheses, add double quotes or single quotes and then type whatever you want to print. In programming terms, we usually call text a string:

print("I am Beh from Dev Hive")

So, this is your first Python program. Now to run this program, just click on the green icon that is located on the upper right side.

As you see, my name and my Udemy account name, is printed here:

Now you know that we can enclose a text (or a string) in either single quotes (‘) or double quotes (“), but what’s the difference?

Note that we should use double quotes when we have single quote inside a string:

print("I'm Beh from Dev Hive")

And we should use single quotes, when we have double quote inside a string:

print('I am Beh from "Dev Hive"')

We can also use triple quotes like this:

print('''I'm Beh from "Dev Hive"''')

In this way, you can use double quote and single quote in your string at the same time.

Print a multi-line string

To print a multi-line string, we use triple quotes like this:

I'm Beh 
from "Dev Hive"

The output of this program is this:

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *