Design a site like this with
Get started

Python : Basic Syntax

python book

Today we will be covering basic syntax of python

Printing any string

python provided print function to print any string

 print("Hello, World!")

Comments in python

“#” is getting used to comment in python

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

Python interpreter also supports comment in below format with three dots

This iscomment

Python Variables

In Python, variables are created when you assign a value to it:

a = 335
b = "Hello, World!"

Python Indentation

python used space to indicate block of code.

Below is example for wring indentation

Now we are correcting it and rerunning.

Before print we have added space so code of block is correctly indented

Multi-Line Statements

Python supports multiline statements with below syntax so you can have code written on multiple lines

print("multiline comment" + \
      "multiline comment" + \
      "multiline comment"

Below is example

Sample code for your reference

print("Hello World")
if 5 > 2:
    print('5 is greater')

print("multiline comment" + \
      "multiline comment" + \
      "multiline comment"

x= 2 + \
   3 + \

print("value of " , x)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: