Python Programming

Input and Output

No program would be complete is it didn’t have a way to receive input from the user.

To receive input from the user in the Python programming language, we use the input() function.

The input() function is assigned to a value called a variable. Text is placed in between the brackets which serve as a prompt for the user.

Receiving input in the Python programming language.

The code above shows how to receive a value from the user. The value is then stored in a variable called name.

The value inside the name variable can then be printed out to the screen.


Concatenation in Python

Concatenation is the joining of strings. In the Python programming language, the “+” is the concatenation operator.

In the example above, when you have a number, you must convert it to a string before you can concatenate it.

Function Overloading

length = input("Please enter the length of the square: ")
length = int(length)
area = length * length
print("The area of a square of length", length, "is", area)

Above is a simple program to find the area of a square. On line 2, the value received by the user is converted into an integer.

On line 4 when we print the output, we get the following output:

Note that the output has added spaces whereas, in the original program, we had none.

Overloading simply means that there are many ways to call a function.

Learn Python in One Week

If you want a quick and easy introduction to the Python programming language, you should check out my fifth book: Learn Python in One Week on the Amazon store.

Leave a Reply

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

%d bloggers like this: