You are on page 1of 3

MOTHER TERESA SENIOR SECONDARY COED SCHOOL

SUBJECT – COMPUTER SCIENCE


NOTES CLASS XI CHAPTER 2-(PYTHON FUNDAMENTAL)

Python has 265 characters set. Character set is a set of character that a language can recognize. A
character set represent any latter , digit or any other symbols. Python has following character set
Letter A-Z , a-z
Digit 0-9
Special symbols space,+,-*,/,**,\,( ),{},[ ], //,=,!=,==,<,>,’,”’,’’’, ; , : ,% , ! ,&, #,<=,>=,@, _
White space Blank space, tab(→) ,carriage return ,new line ,form feed
Other character All the ASCII and Unicode character are part of python

TOKEN-The smallest individual unit in a program known as a token.


Python has following tokens
Keywords-These are special or reserve word that convey a special meaning to the language
Interpreter. Some keywords of python programming are
Ex-if,else,elif,None,import,print etc.

Identifier(Names)-These are the fundamental building block of the program generally used for
given the name of different part of the program viz.variable ,object, class, function etc.
Some rules for forming identifier
1) Identifier is the long sequence of letters and digits.
2) First letter must be as letter or underscore(_).
3) Uppercase and lowercase letter all characters are valid.
4) Digit 0 to 9 can be a part of identifier except for the first letter.
5) Identifier are unlimited in length.
6) An identifier must not be keyword.
7) It can not contain special symbols except underscore(_).

Literals(constant value)-Literals are the data items that has a fixed value and never change during
whole program. Python allow several kinds of literals:
(i) String literals-The text enclosed in single quotes or double quotes form a string literals
‘a’, ‘abc’ , “abc” are the example of string literals.
(ii) Numeric literals-It belongs to two type of value integer and float (decimal).
(iii) Boolean literals- It is used to represent two Boolean value True(1) or False(0).
(iv) Special literal None-Python has a special literal used to indicate absence of value in
variable.It also indicate the end of the list.

Operators- Operators are tokens that trigger some computation/ action when apply on variable and
other object in an expression.
They are divided into two categories:-
Unary Operators –They are operate on one operand means one operator operate on one operand.
Ex- Uninary plus (+), Uninary Minus (-) etc.

Binary Operator-They required two operand to operate upon.Following are some binary operator;
(i) Arithmetic operators- +,-,*,/,%,**,//
(ii) Bitwise operator- &(AND),^(XOR),|(OR)
(iii) Shift operator-<<(shift left),>>(shift right)
(iv) Identity operator-is, is not
(v) Relational operator-<,>,<=,>=,==,!=
(vi) Assignment operator-=,+=,-=./=,*=,%=,**=,//=
(vii) Logical operator-Logical AND, Logical OR
(viii) Membership operator-in, not in

Punctuator-these are symbols used in programming to organized programming sentence or


structure indicate the emphasis of expressions ,statements and programming structure.
Most common punctuators are : ‘, “ ,# ,\ , ( ), , ,: ,= etc.

Barebones of a python of program


(i) Expression-An expression is any legal combination of symbols that represent a value.
Some expression are:
C=a+b ,a+5 ,(a+b)/5
(ii) Statement-A statement is a programming instruction that does something i.e. some action
take place .
print(‘hello’) # this statement called print function
(iii) Comments-These are the additional readable information to clarify the source code. Write
single line Comment in python by using # and multi-line by using ‘’’ or “””. Multi-line
comment is also called docstrings.
(iv) Functions- A function is a code that has a name and it can be reuse(execute again) by
specifying its Name in the program ,where needed. The statement indented below def
statement is part of the function.
(v) Block and Indentation- A group of statements which are part of another statement or a
function are called block and code block. Many language such as java ,C,C++ use
symbols like curly brackets to show block but python does not use any symbol for it,
rather it use indentation.

Variable- Variable is a labeled named location used to store value and whose value can be used and
processed during program run.
Syntax of creating a variable
Variable name=value
Ex- a=13
b=int(input(‘enter a no’))
name=’jacob’
Lvalue and Rvlue-
Lvalues- Expression that can come on the left hand side of an assignment.
Rvalues- Expression that can come on the right hand side of an assignment.
Ex- a=23
b=2*b
In this example a and b are Lvalues and 23 and 2*b are Rvalues.
Multiple Assignment-
1.Assigning same value to multiple variable
a=b=c=10
2.Assigning same value to multiple variable
x.y,z=10,20,30
x,y=y,x
a,b,c=b+2,a+1,c-1
note-A variable is define only when you assign some value in it. Using an undefined variable in
expression/statement cause an error called name error.
Dynamic Typing-A variable pointing to a value of certain type, can be made to point to a value of
different type.This is called Dynamic Typing.
Ex- a=25
a=’hello’
If you want to determine the type of the variable means what type of value does it point to. You use
type in following manner.
Syntax- type(variable name )
ex- a=10
type(a)
<class ‘int’>
a=20.5
type(a)
<class ‘float’>
a=’hello’
type(a)
<class ‘str’>

Simple INPUT and OUTPUT statement


In python to get input from the user, you can use built in function input( ).
Syntax –variable=input(‘massage to be display’)
Note – The input( ) function always return a value of string type.
Reading Number- when you perform an operation on a variable or the data type of the variable is not
suitable (dividing or multiplying a string) python raise error called TypeError.
Ex-age=input(‘enter age’)
age=age+1
TypeError must be string not int
To solve this problem python offers two function int( ) and float( ) to be used with input( ) to convert
the value received through input( ) into int and float types.you can use int( ) and float( ) fuction with
input( ) to change the data type of input value to integer and decimal respectively.
While entering numeric value through input( ) along with int( ) and float( ) make sure that you enter
values that are convertible to the target type other python will raise error.

In python for print a object or message that you give use built in function print( ).A print( ) function
without any value or message print blank line.Python automatically added a newline character in the
end of line printed so that the next print( ) prints from the next line means by default print( ) take
value for end argument ‘\n’- the newline
character. If explicitly give an end argument with print( ) function then the print( ) will print the line
and end it with the string specified with the end argument.
Ex- print(‘My name is amit’, end=’$’)
print( ‘I am 16 year old’)

output as:
My name is amit $I am 16 year old

You might also like