How Python Syntax Works?

In this tutorial we discus some basic points of python syntax Like

How to write In command prompt,

Python Indentation,

Python Variables,

Python Comments.

Python Execution In Cmd Prompt:

Python syntax can be executed directly within the command line, like:

>>> print("Hello World.")
Hello World

Or by creating an above python file on desktop or server by name like example.py(.py) is extension name to save python files and then run that file directly with command prompt by typing this command,

c:\Users\LingarajTechhub> python example.py

When you type the above command the file executed and return some success statements or shows errors.

Python Indentation:

Indentation means proper spaces while programmer or coder writing the python code because its very important.

In other programming languages indentation is not very important because most of the programming languages use curly braces ” { “ whereas in python the coders are uses Indentation.

By help of indentation python defines the block of code.

Example Of Python Indentation:

if 8>2:
   print("8 is greater than 2")

The above code gives output 8 is greater than 2, while

if 8>2:
	print("8 is greater than 2")

Here we are not using proper indentation so the output of above code gives error.

The number spaces is up to you as a programmer how many indent or spaces are given but ultimately we give only one space.

if 6 > 2:
 	print("Five is greater than two!") 
if 6 > 2:
    print("Five is greater than two!")

The above code is a different block so if you give a different indentation it allows but please watch the below code,

if 6 > 2:
 	print("Five is greater than two!") 
        print("Five is greater than two!")

The above code single block with different indentation it’s not allowed on python indentation rules.

So while we are using indentation in python programming the programmer need some cautious about the indentation.

Python Variables:

In python the variables are created when user assign values on it.

x = 5
y = "Welcome To Python World!"

Python has no syntax for declaring a variable.

Python Comments:

For In-code documentation we are using comments inside lines of code.

Python has also In-Line code comments are uses for code documenting for future analysis ok. Like,

>>> print("Hello Python!") # Here print means to show result on console

The above code the inline comment is # to know what is the working of print in python.

If you find any issue and rewrite this article then contact us.

Default image
Lingaraj Senapati
Hey There! I am Lingaraj Senapati, the Co-founder of lingarajtechhub.com My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.
Articles: 190

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply