NB: Put the Python code in the ‘main.py’ file already created when we create a new project in Python and Run or Execute by clicking the run button (horizontal green color triangle symbol above in standard toolbar) by selecting the file name in the drop-down box.

Example : How to use Comment Line in Python?
#Sinlge Line Comment

# print("Hello India")     Sinlge Line Comment
# print("Hello World")
# print(100)

-----------  OR  ------------

""" This is Multiline Comment
in Python programming languages """

Output:
No output due to applied comment line symbol # and """.
Example : How to Print/Display messages in Python?
print("Hello India")
print('Hello India')
print("Hello India");
print("Hello", "India");

print("Hello World", "Hello India")
print("Hello World"   "Hello India")

print(100)
print("100")
print(100);
print(100,200,300)

print(100,'Hello India')
print(100,335.35)

print(100.35)

print(100+50j)      # Prints Complex Number

Output:

Hello India
Hello India
Hello India
Hello India

Hello World Hello India
Hello WorldHello India

100
100
100
100 200 300

100 Hello India
100,335.35

100.35

100+50j
Example : How to Print/Display Messages in Multiple Lines (New Line) in Python?
print("Hello World")
print("Hello India")

Output:
Hello World
Hello India

NB: Python by default show new line output.

-----------  OR  ------------

print("Hello World\nHello India")

Output:
Hello World
Hello India

-----------  OR  ------------

import os
msg = 'Hello'+ os.linesep + 'world'
print(msg)

Output:
Hello
World

-----------  OR  ------------

nl = "\n"
print(f"Hello{nl}"
      f"World{nl}"
      f"India")

Output:
Hello
World
India

NB: print(f...)is a formatting print method.

-----------  OR  ------------

data = print("Hello", "World", "India")
print(data)

Output:
Hello World India
None

NB:
The print()function always returns a value None with variable output.
Example : How to add a Customized Separator Symbol in the whole output in Python?
print("Hello", "World", "India", sep='-')
print(10, 20, 30, sep='')
print(10, 20, 30, sep='_')
print(100, 200, 300, sep='  ')
print(100, 'Python', 'Oops', sep='**')

Output:
Hello-World-India
102030
10_20_30
100  200  300
100**Python**Oops
Example : How to add a Customized Separator Symbol at the End of a message/output in Python?
print("Hello", "World", "India", end='_')
print(100, 200, 300)

Output:
Hello World India_100 200 300

-----------  OR  ------------

print("Hello", "World", "India", end='_')
print(100, 200, 300, end = '***')

Output:
Hello World India_100 200 300***
Example : A Python program to see the List of Python Keywords.
import keyword
print(keyword.kwlist)

Output:
['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Loading

Categories: Python Theory

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.