Notes On Python Fundamental
Notes On 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
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
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’>
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