Assessment 7
Next Topic: Command Line arguments
Previous Topic: Mathematical Functions
Related Video:https://www.youtube.com/watch?v=-AJntqLTi94&feature=youtu.be
1. What is the difference
between = and == operators?
a=10
b=20
=
|
==
|
a=b
|
a==b
|
i.e: we are
assigning the value of variable ‘b’ to the left hand side variable ‘a’
|
We
comparing two variables, which returns Boolean True/False
|
print(a)
|
print(a==b)
or print(b==a) # compares, we get result True or false
|
Output: 20
|
Output:
True
|
2. Find out the output of the following program
a=10
b=10
print(a is b)
x=True
y=True
print(x is y)
output:
True
True
3. “Python is my favorite
Programming language”
How to find the “favorite” is existing or not in the string?
Ans:
>>>
a="Python is my favorite Programming language"
>>>
print("favorite" in a)
True
>>>
4. If a=20, b=30
(a) Convert
from decimal to binary (b) find the a&b (c) a|b
Ans:
(a) a=10100,
b=11110
(b) a&b=20
(c) a|b=30
(5.) Find out
the a=25, (i) calculate a>>2 (ii) calculate a>>3
Ans:
a=11001
a>>2
6
>>> a>>3
3
(6.) Evaluate
the expression: 3/2*4+3+(10//4)**3-2
Ans: 15.0
(7.) What is
split() function?
Ans:
The split()
method splits a string into a list.
You can
specify the separator, the default separator is any whitespace.
Example:
"2
4".split() #We have to call the split() function w.r.t string
['2', '4']
>>>
"1, 2 3 Hyd, Vij Kurnul,Kadapa atp".split(',')
['1', ' 2 3
Hyd', ' Vij Kurnul', 'Kadapa atp']
>>>
(8.) Find out the output
a = 21
b = 10
c = 0
c = a + b
print ("c = a + b is ",
c)
c += a
print ("c += a is", c )
c *= a
print ("c *= a is", c )
c /= a
print ("c /= a is ", c )
c
= 2
c %= a
print ("c %= a is", c)
c **= a
print ("c **= a is", c)
c //= a
print ("c //= a is", c)
Ans:
When you execute the above
program, it produces the following result −
output:
c = a + b is 31
c += a is 52
c *= a is 1092
c /= a is 52.0
c %= a is 2
c **= a is 2097152
c //= a is 99864
>>>
9. List out the bit wise operators in python.
Operator
|
Name
|
Description
|
&
|
AND
|
Sets each bit to 1 if both bits
are 1
|
|
|
OR
|
Sets each bit to 1 if one of two
bits is 1
|
^
|
XOR
|
Sets each bit to 1 if only one
of two bits is 1
|
~
|
NOT
|
Inverts all the bits
|
<<
|
Zero fill left shift
|
Shift left by pushing zeros in
from the right and let the leftmost bits fall off
|
>>
|
Signed right shift
|
Shift right by pushing copies of
the leftmost bit in from the left, and let the rightmost bits fall off
|
10. Convert this string to
lowercase? (PYTHON)
Ans: string='PYTHON'
print(string.lower())Next Topic: Command Line arguments
Previous Topic: Mathematical Functions
Related Video:https://www.youtube.com/watch?v=-AJntqLTi94&feature=youtu.be
No comments:
Post a Comment