Simple Arithmetic, Input and Output in Python

Text Output

The built-in print() function of Python is used to display output on the command line terminal. There are alternative uses of this function as shown in :

print ("Learning Python is interesting.")

Output: Learning Python is interesting.

print ("Learning Python is interesting.","Right?")

Output: Learning Python is interesting. Right?

print ("Learning","Python","is","interesting.","Right?")

Output: Learning Python is interesting. Right?

String Literals

String literals are expressed between a pair of double quotation marks.

Escape Characters

Similar to using quotation marks in a string literal escaped by the \ character, the backslash itself can be used inside the string by escaping it again with another backslash:

print("Here is a single backslash \\ used in a string literal")

Output: Here is a single backslash \ used in a string literal

Another escape character is the \n newline character that we can use to split the string literal into multiple lines:

print("Here is a newline \n used in a string literal")

Output:

Here is a newline
used in a string literal

It is also possible to use \' as the single quote, and \t as a tab character inside the strings.

print() Function Arguments

The print() function automatically adds a newline to the end of the output, we can eliminate that new line at the end using a special format as in:
print("This output does not have a newline at the end", end='')
print(" so that the next call to the print() can continue outputting on the same line.")

Output:

This output does not have a newline at the end so that the next call to the print() can continue outputting on the same line 

You can also change the separator character for the print() function:

print("this","is","an","example","to","changing","the","default","separator","space","character", sep='_*_')

Output:

this_*_is_*_an_*_example_*_to_*_changing_*_the_*_default_*_separator_*_space_*_character

print ("10 times 2 is",10*2)
print ("2 to the power 3 is",2**3)
my_age = 20
city = "Istanbul"
print ("Age is",my_age, ". I live in ", city)

You can experiment with the given source code using the following example: