DEV Community

David Bosah
David Bosah

Posted on

PYTHON BASICS: Working with input and print functions.

INTRODUCTION

The most basic functions to get used to in Python language are INPUT and PRINT functions. Surprisingly as simple as they seem, you need to grasp their importance and gain mastery in them to progress smoothly as a python programmer.

Let's start with a simple definition; The Print function tells you what will be displayed for the user to see. For instance, Printing (“Hello World”) means that the user sees “Hello World” on display.

On the other hand, the input function takes in given data. For instance Input (“What's your name”) means that the user is expected to answer this question with a response that will be stored and used.

PRACTICAL EXPLANATION
For better grasping of these concepts let's quickly run through a little project together. Imagine you are single(which you probably are, lmaoooo) and you decide to find a date from a dating site, picture the welcome message you will get and a possible question that will follow it; a question that intends to find out your location. Let's also assume that the site was created by an American that also expects his target audience to be Americans,

print("Welcome to the coolest dating site ever!!!")

print("We would love to know where you are from.")

date = input("United States or Overseas")

Enter fullscreen mode Exit fullscreen mode

The above code will appear this way:

Welcome to the coolest dating site ever!!!
We would love to know where you are from.
United States or Overseas:

The necessity of defining "date" is that in the case of using another function like the "if else" function you could easily describe the entire line of code ("United States or Overseas") as'date'.

To understand this better, let's expantiate a little and finish the code with an "if else" function that indicates that if the person is from United States, the name of the particular state in US should be requested. On the other hand if the person is from Overseas, the country the person is from should be requested.

To achieve this, this is what your code will look like:

print("Welcome to the coolest dating site ever!!!")

print("We would love to know where you are from.")

date = input("United States or Overseas")

if date == "United States":
    print("What State In USA is it:  ")
else:
    print("What country are you from:  ")
Enter fullscreen mode Exit fullscreen mode

Remember that You are from the United States, So:

Welcome to the coolest dating site ever!!!
We would love to know where you are from.
United States or Overseas: United States

Now you have chosen United States, the next thing you will see is:

Welcome to the coolest dating site ever!!!
We would love to know where you are from.
United States or Overseas: United States

What State In USA is it:

CONCLUSION
In summary the idea of Input function is to request for information from the user while print is to display a response or even an instruction.

Top comments (0)