Home » Python

Find output of Python Programs | Set 1 (Basics)

Here, we have some of the Python basic programs, and we have to find their outputs. Each program has correct output along with their explanation.
Submitted by IncludeHelp, on August 14, 2018

Program 1:

print "Hello",
print "World"

Output

    Hello World

Explanation:

There is a comma after the statement print "Hello", it prevents to print the new line after printing the message and inserts a space after the message.

Thus, first statement will print "Hello " ("Hello" and a space) and second statement will print "World" and then new line.

Thus, the output will be "Hello World" and after that, if we print any message - that will be printed in separate line.


Program 2:

print "Hello", "World"

Output

    Hello World

Explanation:

There is a comma after the statement print "Hello", it prevents to print the new line after printing the message and inserts a space after the message.

Thus, first statement will print "Hello " ("Hello" and a space) and second statement will print "World" and then new line.

Thus, the output will be "Hello World" and after that, if we print any message - that will be printed in separate line.


Program 3:

print 'Hello World'
print "Hello World"
print '''Hello World'''
print """Hello World"""

Output

    Hello World
    Hello World
    Hello World
    Hello World

Explanation:

Print with single quotes, double quotes, triple single quotes and triple double quotes prints the text. Thus, the output is same.

One difference is there, normal single quotes and normal double quotes prints single line text, while triple single quotes and triple double quotes are able to print multiple line text.


Program 4:

print '''Hello 
World'''

print """Hello
World"""

print """Hello
               World"""

Output

    Hello 
    World
    Hello
    World
    Hello
                   World

Explanation:

As we mentioned in the explanation of question3 that triple single quotes and triple double quotes print the text as it is written i.e. in multiple lines also.




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.