12 Lecture Note Unit 1 Output Function Pcps 2023
12 Lecture Note Unit 1 Output Function Pcps 2023
Lecture Notes
Python for Computational Problem Solving
UE23CS151A
Lecture #12
Output function
By,
Prof. Sindhu R Pai,
Anchor, PCPS - 2023
Assistant Professor
Dept. of CSE, PESU
Verified by,
PCPS Team - 2023
Many Thanks to
Dr. Shylaja S S (Director, CCBD and CDSAML Research Centers, Former
Chairperson, CSE, PES University)
Prof. Chitra G M (Asst. Prof, Dept. of CSE, PCPS Anchor – 2022)
Aug – Dec, 2023
Observation: Runs one statement at a time. Here, we need not tell the interpreter what to
be displayed because of the statement execution. When you press the enter key, the result
is displayed without any extra instruction like print. It does the same job when you use the
print function in interpreter mode.
Batch mode
Observation: No output from the first four lines of code. Output of next three lines are there
in the output window. Here, we need to explicitly tell the interpreter what should be
displayed as a result of the program. Python has a specialized function that does just that,
called the print function.
Note: In Batch mode, we must use the function print for displaying information to the
output screen
Function: A group of commands that performs a specified task. It may take some input, do
some processing, and returns a result(output). In programming, input given to a function
are called arguments. For more details, refer to Lecture #51
Print in detail :
Print is a function that takes input and as part of the processing, displays the value of
the argument to the output screen. We will be calling this print function using a call operator
(). Let us get the help page of print to understand it better.
Few Examples:
Example 1: Can take any type of arguments
In all above examples, we see that if there is more than one argument to print, they are
separated by a space and between two print calls, there is a new line in the output. This is
because of the keyword parameters sep and end respectively. The default value for sep is
space (‘ ‘) and the default value for end is ‘\n’ (newline).
Example 5:
Now think about printing only 2 digits after the decimal point in each expression like
5/7. Possible using the format function in python. The built-in format function can
be used to produce a numeric value containing a specific number of decimal places.
More about this will be discussed in Lecture #17.
Example 6:
- END -