Hello world | Comments in Python | Escape character | Example | Practical Question

Hello coders,

Today we will learn to print Hello world,How to use comments in python ,Escape character,How to live a line,\n,\t,\r,Finally we will go through some practical question.


Printing in Python

print("hello world")


Run an Online python compiler Here and test it.

Not only hello world but you can print any text in python console use print keyword.

print("any text here")

Printing Hello World In Python

Comments in Python | why we need comments

  •  Suppose you are writing a Python program which is very vast.You can't remember why you have used that piece of code.Here comes the use of comment.
  • Or suppose you have to present this code to a non technical person then you can use comments to specify why you have written that piece of code.
  • Comments are not executed by compiler.

''' your comments go here'''


Use of comment ---

'' Below code is used to print hello world'''
print(''hello world''')

You can see in above example how comment was used to specify why the code was written.


How To Comment in Python

Escape character | Uses of escape character


You might be thinking what is escape character in Python as the name suggest they are special character to live space or either live line

\t ---  Use to live a tab space.For living multiple space you can use multiple \t.

Use of \t----

print(''live /tspace'')


USE OF \t

\n -- Used for living a line.For living multiple line you can use multiple  \n.

Use of \n--

print("live\nline")

How to use \n in Python

Pactical Example


1. Print hello     world on python console.

    print("hello \t\t world'')

2.Print     hello    on python console
               
                world
    print("hello \n\nworld")

3. print following pattern

print("\t*\n*\n\t\t*\n*\n\t\t\t*")

explanation to this


Questions for you in Python

1.print following pattern
    



You can send answer to this question to us and get 24*7 support here

Comments