0% found this document useful (0 votes)
35 views

Python Syntax

The document discusses various Python code commenting techniques and syntax rules. It explains that # is used for single line comments and multiple # can be used for multiline comments. Semicolons after statements are optional in Python. Indentation rather than brackets or semicolons indicates code blocks in Python. The print() and input() functions are demonstrated for output and user input. Python is case-sensitive, so uppercase and lowercase variable and function names are treated as different.

Uploaded by

Kaushik Ray
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Python Syntax

The document discusses various Python code commenting techniques and syntax rules. It explains that # is used for single line comments and multiple # can be used for multiline comments. Semicolons after statements are optional in Python. Indentation rather than brackets or semicolons indicates code blocks in Python. The print() and input() functions are demonstrated for output and user input. Python is case-sensitive, so uppercase and lowercase variable and function names are treated as different.

Uploaded by

Kaushik Ray
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Creating a Comment

Comments starts with a #, and Python will ignore them:

In [ ]:
#print("Hello, World!")

print("Good Morning")

Multi Line Comments


Python does not really have a syntax for multi line comments.

To add a multiline comment you could insert a # for each line:

In [ ]:
#This is a comment

#written in
#more than just one line

print("Hello, World!")

Semicolon (;) is optional at the end of the statement in Python


In [ ]:
a = 5

print(a)

b = 19;

print(b)

The semicolon in python is used to denote separation rather than termination.


In [ ]:
print("hii");print("hello");print("good morning")

The print () function, we display output on the screen in python


In [ ]:
print("Good Night")

The input () function, we take input from a user


In [ ]:
name = input("enter your name")

print(name)

Indentation in Python
Indentation means white spaces are used to delimit a block.Python uses a combination of colon (:) and indentation to indicate a block

In [ ]:
if 5>2:

print("Five is greater than two")

In [3]:
if 5>2:#proper spacing is not given.o it throws error

print("Five is greater than two")

File "C:\Users\Lenovo\AppData\Local\Temp/ipykernel_29820/1392400328.py", line 2

print("Five is greater than two")

^
IndentationError: expected an indented block

Python is casesensitive
It means it treats Uppercase and lowercase differently

In [2]:
print("Hello World")

Print("hello")#Print is in Uppercase,so it throws error

Hello World

---------------------------------------------------------------------------

NameError Traceback (most recent call last)

~\AppData\Local\Temp/ipykernel_29820/3335447303.py in <module>

1 print("Hello World")

----> 2 Print("hello")

NameError: name 'Print' is not defined

In [ ]:

You might also like