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

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.