Friday, June 8, 2018

Print Function , Indentation and Comment in Python






Print Function





The print function is used parenthesis ().

Between Parenthesis () you can write String, Number, Variable etc to print on the screen or console.

EX: print (‘Hello world !’) 

# print is a built-in function

# ‘Hello world’ is a string between parenthesis

# String Can be written between ‘ ’ or “ ” . 


Output: Hello world

The Print function insert a new line at the end, by default.

print(“Hello world!”, end=”\n\n\n “) # Appends a space instead of a newline.

For new line \n is use. (\n escaped new line)

Ex: print(‘Hello Everyone\n welcome to justseeker.com’)


Output: 

Hello Everone
welcome to justseeker.com




Creating a python file


Just create a new file with .py extension (example.py)

To run example.py type python example.py on IDLE (see video to more information)

Examples : In exmaple.py write a following code

print(“I Love Python”)

a = “I Love

#Two objects are Passed

print(a , “Python”)

b = “coding

print(a, “Python”, b )


Output of above code:

I Love Python

I Love Python

I Love Python Coding







Indentation


Python uses indentation to indicate a block of code .

Indentation is very Important in python.

Example of indentation:
If 10 > 5:

print(“Ten is greater”)


if you are not using indention python give error

Example not use indentation:

If 10 > 5:

print(“Ten is greater”)


Output:

SyntaxError: invalid syntax








Comment in Python



Python comments start with #,

Example;

print(‘Hello World!’) # This is a print function

# comment not render by python


Now what will do if you want multiline comment

answer is you can use docstrings

Docstring is capable to one line or multiline comment.

"""This is a


multiline docstring ."""


print("Hello, World!")






Prev: Print Function , Indentation and Comment    

Next: Variable Types in Python 3





Thank You Please Subscribe to get latest update and Comment below

1 comment:

  1. Nice Explanation Here Clear my some thank you!
    I an waiting for next Topic

    ReplyDelete

Google+ Followers