Logical opretors:
1. Logical and
2. Logical OR
3. Logical NOT
Bitwise operator:
1. Bitwise and (&)
2. Bitwise or r(|)
3. Bitwise ~ (not/complememt/negation)
4. Bitwise ^ (XOR)
5. Bitwise << (left shift)
6. Bitwise >> (right shift)
Assignmemt opretor:
It dosnt return any value
It helps to intialize (stores a value ) OR re-initialize (update the existing ) a memory
location.
Syn:
#Initilization
named_memory loca= val/initilized_val
id it is a unique integer repesentation generated by PVM based on the allocated memory
and the val stored
To display the id of a varibales a pre-defined function is used i.e., id()
Id is store base on the memory addres and val assign
Variables :
It is a container to store a val
It is a name given to the memory
Variable can hold only single val data but we are thinking (it is initilizing in the same
memory)
Rules:
It is compulsory to intialize a var before utilizing
If we try to strore same val into multiple variables, then a sinlge shared memory will
be provided to all the varibles
If we try to update any single varible that was pointing to the shared memory then a
new memory will get assigned without distrubing the exisiting memory
It we try to assign multiplr values into the same var one after the other then, the
varible will hold the latest updated val
If we try to assign multiple values into the same variable together at the same time
then the PVM will internally convert it into a tuple
Internally after re-initilizing the same var with multiple values one after the other
PVM keeps allocating new memory for each updation.
Types of assignment operator:
Combination of
A. arthmatic with assignment
+=, -=,*=,**=,//=, /=, %=
B. Bitwise with assignment
&=, |=, ^=, <<=, >>=, are called as compound statement.
Rules:
It is complusary initilize the var before utilizing it.
Minimum of 2 opreands are required in a given expression to implement compound
statement.
One of the oprands should be a variable that is used commonly on RHS for opreation
and LHS for updation.
In the compound statement the operation specified on the RHS will be executed first
that is the assigning operation will be done at the last
The common operand that is being utilized on the RHS for operation and LHS for
assignment should be placed on the LHS of the operation.
Note:
~= is not being supported as it reuires only a single operand to perform the operation,
where as compound statement require minimum of operands.
Membership operator:
Iterable objects: The objects that can hold multiple individule ele’s into the same shared
memory location.
Eg: list,string, tuple,set, dictionary
Identity operator:
Returns boolen value
It just compares and check whether the ID of the given two operands are similar or
not.
Control flow statement:
It helps to control the execution flow of the program
Typrs of control statement:
1. Conditional statement: execute a condition
A. Simple if
B. If – else
C. Elif ladder/if-elif
2. Looping satement:
A. for
for with range()
Incre
Decre
for without range()
B. while
incre
decre
C. jumping statement:
break,continue,return
A. ‘for’ loop with range():
range():
o syntax:
range(start, end/stop, updation)
o It is predefined function to setup a sequnce of values based on mentioned
start till the mentioned end.
o Only integers can be passed as the input.
Start:
From where the sequence should begin
Default start0
End/stop:
“till” where my sequence should exceute.
Compulsory values to be passed.
Updation/step:
Difference between current and the next values
Default step: +1
range function can’t written sequnce of values by itself therefore to fecth each individual
value in the range for loop should be uesd with it.
For loop uesd when ever we know the start and end value.
Syntax:
for var_name in range(start,end,step):
#logic
#remaining statement to be execute
Types of for loop:
A. Incre “for” loop:
Syntax: for var_name in range(start,actual end + 1), positive step):
#logic
#rem statement
Eg: WAL to print 2 to 8 with diffrence of 3
Tracing rules:
1. Step: positive stepdecre loop
2. Start < mentioned end
3. If you need to inclued end value also,actual end + 1.
B. decre “for” loop:
Syntax: for var_name in range(start,actual end - 1), negative step):
#logic
#rem statement
Eg: WAL to print 10 to 1 in a decrementing order with diffrence of 4
Tracing rules:
4. Step: negative stepdecre loop
5. Start > mentioned end
6. If you need to inclued end value also,actual end – 1.
While loop:
Leap year:
Identify the major logic and copy it
Include a function declaration and paste the logic within it
Analyze the i/p requried by the function to execute the logic
Design the o/p statement
Call the function and store the o/p if any,to reuse it
1. Write a program to print all the leap year’s present in a user defined range.
Eg: sr=1999 er:2003
Leap yesr’s:
2000
2. WAP to print leap year and non leap year
Count digits:
WAP to count a number of ditits in a given number.
Eg: n=2456 o/p: 4
n=0004 o/p: 4
n=-123 o/p: 3
Using function:
Factors:
Without using a fuction:
Fibonacci series:
The initial 2 position val’s is 0 and 1
The next position val’s is the sum of the previous 2 position val’s
1<=pos<=natural num