Thursday 9 September 2021

Program in python

As we learned about syntax in our previous article which is the introduction of python. Python syntax can be executed by writing directly in the command line.

      print("Hello, Python!")

To create a python file in the IDE, we use the .py file extension and run it in the command line.

    c:users\ name >python file.py

Python Indentation

In python, indentation is very important it’s used to indicate a block of code. Where in another programming language the indentation in the code is for readability only.

Example

if 2 > 1:

  print("one is smaller than two!")

Note:- python will give an error if skip the indentation.

Example

Syntax error:

if 2 > 1:

print("one is smaller than two!")

Comment in python

·         It is used to explain the python code.

·         It is used to make the code more readable.

·         It is used to prevent execution when testing code.

·         Create a comment in python with #, and python will ignore them.

 

Example

                #This is a comment

             print("Hello, Python!")

 

Example

      print("Hello, python!") #This is a comment

 

Example

   #print("Hello, Python!")

             print("hello, python3.9!")

Multiline comment

·        Python uses triple quotes for long comments in the python program.

·         To add multi-line comments insert a # for each line.

Example

   #This is a comment

   #written in

   #more then just one line

  print("Hello, Python!")

Example

            """This is a comment

                 written in

                 more than just one line"""

               print("Hello, Python!")


 

 

1 comment: