Operators and Operands in Python - 12th CBSE

Operators are special symbols that represent computation like addition and multiplication. The values
that the operator is applied to are called operands. Operators when applied on operands form an
expression. Operators are categorized as Arithmetic, Relational, Logical and Assignment. Following is the
partial list of operators:
Mathematical/Arithmetic operators: +, -, *, /, %, ** and //.
Relational operators: <, <=, >, >=, != or <> and ==.
Logical operators: or, and, and not
Assignment Operator: =, +=, -=, *=, /=, %=, **= and //=
Program need to interact with end user to accomplish the desired task, this is done using Input-Output
facility. Input means the data entered by user (end user) of the program. In python, raw_input() and input (
) functions are available for input.
Syntax of raw_input() is:
Variable = raw_input ([prompt])
Example:
>>>x = raw_input ('Enter your name: ')
Enter your name: ABC
Example:
y = int(raw_input ("enter your roll no"))
will convert the accepted string into integer before assigning to 'y'
Syntax for input() is:
Variable = input ([prompt])
Example:
x = input ('enter data:')
Enter data: 2+ ½.0
Will supply 2.5 to x
Print: This statement is used to display results.
Syntax:
print expression/constant/variable
Example:
>>> print "Hello"
Hello
Comments: As the program gets bigger and more complicated, it becomes difficult to read it and difficult
to look at a piece of code and to make out what it is doing by just looking at it. So it is good to add notes to
the code, while writing it. These notes are known as comments. In Python, comments start with '#' symbol.
Anything written after # in a line is ignored by interpreter. For more than one line comments, we use the
following;
Place '#' in front of each line, or

Use triple quoted string. ( """ """)

No comments:

Post a Comment