Python programming tutorial (Part 2) - Printing Function (optional Arguments).

in #steemiteducation2 years ago (edited)

Hello everyone! I'm here again with another interesting lesson on Python programming. And today I will be emphasizing on the print function. So Let's get started.
$_20 (1).JPG

Printing in python:

The print function is a command we use to instruct the program to print/display an output. Here is an example.
The print function as you can see requires parenthesis around it's argument. And as you can see from the code above the argument is the string Hello Python. In Python anything inside the quotes, with a few exceptions, will be printed out exactly as it appears.

Don't worry about the exceptions as I'll be treating it in this article. But before then let's see the difference between integers in quotes vs intergers without quotes. What you should understand is that anything written in quotes using the print function is interpreted by the computer as a string, and the computer will display it exactly as written in the code. And on the other hand intergers written without quotes is interpreted by the computer as a problem that needs to be evaluated. Here is a simple example.
The above statement will print 5 + 7.
The above statement will print 12.

We also use a comma to print several things at once. Python will automatically insert spaces between them. Here is an example and the output it produces.


Optional Arguments:

The print function have two optional Arguments, the sep and the end. They are not very important, but they can be used to make your outputs look nice.

The sep:

Python will automatically insert spaces between each of the arguments of the print function. But there is an optional argument calledsep, you cause to change that space to something else. For example using sep=':' would separate the argument by a colon.

One good way of using this is to have nothing inside quotes as in sep=''. This instructs the program to put no spaces within the Arguments. Below is an example of how to make your output nice.


The end:

The print function automatically advances to the next line. For example, the following will print two lines.

But you can use the optional argument called end to prevent the print function from advancing to the next line. Here is an example.

Of course you could achieve this better with a single print, but as time goes on you will see the importance of the end argument.

Exercise to try:

  1. Ask a user to enter a number x. Use the sep optional argument to print out x, 2x, 3x, 4x and 5x. Each separated by three dashes like below.

My Advice:

Please ensure you try all the codes in this article for a better understanding. And also attempt all the exercises as well. If you are confused or stuck anywhere fell free to comment below and I or any other programmer in the house will give you a hint.

Thanks for reading patiently! I hope you enjoyed it? Please share your class experience with us. And know that your ideas to make this class a success is also appreciated, just feel free 🙂

My most recent programming articles.

  1. Solutions to my exercises on Python Programming (Part 1).
  2. Python programming tutorial 1–(Installing Python, getting user Inputs and running basic programs)
  3. My new Steemit project and how I intend to run it.
  4. Top 3 reasons why everyone should learn programming.

If you miss any of my tutorial don't worry as you can always visit my page to see all my articles, or click on the #edywill tag to see all my recent programming articles.

To get more programing tutorials, tips and technological updates you won't want to miss out, subscribe to my Steemit page by following @edywill.


Your Post Has Been Featured on @Resteemable!
Feature any Steemit post using!
How It Works:
1. Take Any Steemit URL
2. Erase https://
3. Type re
Get Featured Instantly & Featured Posts are voted every 2.4hrs
Join the Curation Team Here | Vote Resteemable for Witness

Resteemed by @resteembot! Good Luck!
Curious? Read @resteembot's introduction post
Check out the great posts I already resteemed.

ResteemBot's Maker is Looking for Work

You were lucky! Your post was selected for an upvote!
Read about that initiative