0% found this document useful (0 votes)
12 views3 pages

IX Ch-5 Coding in Python

Class 9 coding in python notes

Uploaded by

gunjangupta9386
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

IX Ch-5 Coding in Python

Class 9 coding in python notes

Uploaded by

gunjangupta9386
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Coding in Python Notes

Python Comments
In Python, comments are lines of code that are skipped by the interpreter while the program is being run.
Comments in python can be either written in single line or multiline.

 Single line
In Python, a single-line comment is indicated by the hash symbol (#). Any text following the # on the same line is
treated as a comment and is ignored by the Python interpreter during program execution.

 Multi-Line Comments
Python does not provide the option for multiline comments. However, there are different ways through which
we can write multiline comments.

 Using String Literals as Comment


Python ignores the string literals that are not assigned to a variable. So, we can use these string literals as Python
Comments.
'Single-line comments using string literals'
""" Python program to demonstrate multiline comments"""
print("Multiline comments")

Variables:
Variables are the containers used for storing data value. The value of the data is stored in these containers. Value
of a variable can be a string (e.g., ‘b’, ‘Global Citizen’), numeric (e.g., 345) or any combination of alphanumeric
characters (CD67).

Syntax: variable_name4=variable_value

Rules to follow while writing a variable

1. A number cannot be used as the first character in the variable name. Only a character or an underscore
can be used as the first character.

2. Python variables are case sensitive.

3. Only alpha-numeric characters and underscores are allowed.

4. There are no special characters permitted.

Datatype
Every value belongs to a specific data type in Python. Data type identifies the type of data values a variable

can hold and the operations that can be performed on that data.
Mutable and Immutable Data type:

Variables whose values can be changed after they are created and assigned are called mutable. Variables whose
values cannot be changed after they are created and assigned are called immutable.

Operators in Python
An operator is used to perform specific mathematical or logical operation on values

1. Arithmetic Operator: Python supports arithmetic operators that are used to perform the four basic
arithmetic operations as well as modular division, floor division and exponentiation.
(+,-,*,/,//,%,**)
2. Relational operator compares the values of the operands on its either side and determines the
relationship among them.
a) == equals to b) != not equals to
c) > greater than d) < less than
d) >= greater than or equal to e) <= Less than or equal to
3. Assignment operators
They are used to assign the value of an expression to a variable. These operators are
a) = assignment b) /= assign quotient

c) += assign sum d) *= assign product

e) %= assign remainder f) = assign difference

g)* *= assign exponent h) //= assign floor division


4. Logical operators

These operators are used to make a decision on two conditions. Logical operators are typically used with
boolean values and what they return is also a boolean value. These operators are

a) and : Logical AND b) or : Logical OR

Debugging
Debugging is the systematic process of finding and fixing errors, or "bugs," in software or hardware
to ensure the system functions correctly and reliably. Errors occurring in programs can be
categorized as.
i) Syntax errors: Syntax error occurs when the code doesn't follow Python's rules, like using incorrect
grammar in English. Python stops and points out the issue before running the program.
ii) Logical errors: Logical errors are subtle bugs in the program that allow the code to run, but
produce incorrect or unintended results.
iii) Runtime errors: A runtime error causes abnormal termination of program while it is executing.
Runtime error is when the statement is correct syntactically, but the interpreter cannot execute it.

You might also like