Review of Python Basics End Game
Review of Python Basics End Game
(a)True
O (b) False
75
(c)None (d)Null
⑦
.
25
2. State True or False:
servong :
for control vosable in
#optional
else :
-
-
What is the output of the following code?
---
Text = 'Happy
--
hour12-3'
L= " "
for i in range(len(Text)):
if Text[i].isupper():
-
HAPPY#HOUR112
L=L+Text[i].lower() - 33
elif Text[i].islower():
-
X
L=L+Text[i].upper() -
elif Text[i].isdigit():
-
-
L=L+(Text[i]*2) (A)hAPPY#HOUR1122#33
-
(B)Happy#hOUR12#3
else:
(C)hAPPY#HOUR112233
L=L+'#' -
(D)Happy Hour11 22 33 #
print(L)
1X2
11 2x2 = 22
4. Select the correct output of the code:
s = "Question paper 2022-23“ -
s= s.split('2')
=>
-
to
lis
print(s)
-
a. ['Question paper ', '0', '', '-', '3'] =
b. ('Question paper ', '0', '', '-', '3')
c. ['Question paper ', '0', '2', '', '-', '3'] -
d. ('Question paper ', '0', '2', '', '-', '3')
5. What will be the output of following code if
0111
a = “abcde”
Ab
a [1:1 ] == a [1:2]
-
False
type (a[1:1]) == type (a[1:2])
↑
6. Select the correct output of the code:
s toLupe
a = "foobar"
--
a = a.partition("o")
strins
-
print(a)
(a) ["fo","","bar"]
(b) ["f","oo","bar"]
(c) ["f","o","bar"]
(d) ("f","o","obar") -
-
7. Identify the output of the following python code: 1
L
D={1:"one",2:"two", 3:"three"} -
L=[] =
O -
if 'o' in v:
[1 ]
-
-
=
L.append(k)
- I
print(L)
-
(a) [1,2] (b) [1,3] (c)[2,3] (d)[3,1]
-
8. Which of the following is not a tuple in python? -
(a) (10,20) (b) (10,)
O (c) (10) (d) All are tuples
E)
9. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
-
used
7 Sambull not
in dectionary
a. True b. False
C
c. Error d. None
10. Predict the output of the Python
code given below:
-
T = (9,18,27,36,45,54)
-
②
(18 36 54)
- --
L=list(T)
E , S
-
L1 = [ ] - - -
-
for i in L:
-
9 %6
& -
if i%6==0:
-
L1.append(i) I
GF
-
T1 =- tuple(L1)
print(T1)
③
11. What will be the output of the following Python code snippet?
--
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
-
A
d1 == d2 I
6
a) True -
b) False
c) None
d) Error
12. State True or False
“continue keyword skips remaining part of an iteration in a loop”
=<
Sa
while (ic : 3) :
If (i = = 2) :
continue :
Spent
13. Select the correct output of the code:
01231561
>>> St=”Computer”
-
>>> print(St[4:])
False
or Joue
not and
Take
Faad I
or
I
18. When a Python function does not have return statement then what
it returns? -
print(S) # Statement 2
-
S[0]= '@’
- - #Statement 4
S=S+"Thank you" #Statement 5 -
(a) Statement 3 =
(b) Statement 4
(c) Statement 5 (d) Statement 4 and 5
Using Interactive
-
(Python Shell window) mode, the Python commands
are directly typed at >>> (command prompt) and as soon as we press
the Enter key, the interpreter displays the result(s) immediately, which
is known as Displaying.
0
New option or press the shortcut key Ctrl + N from the shell window.
TOKENS
A token is the smallest element of a Python script that is
meaningful to the interpreter There are five categories of tokens
which are as under
-Identifiers: The name of any variable, constant, function or module
is called an identifier. The Python identifier is made with a
combination of lowercase (a-3) or uppercase (AZ) letters, digits
(0-9) or an underscore (_) Examples of identifiers are abc, x12y,
India_123, swap, stud, Roll, no, etc
Bore * ab
- -
Keywords: The reserved words of Python, which have a special
-
S
DATA TYPES
-----
-
1. Int idata type is used to store whole numbers without Fractional part .
-
They can be +ve of - ve .
-
2. Boolean : bool data type represents one of the two values : True or
False . It is sub type that represents integer values
-
-
1 (True) and 0 (False) .
-
3. Float/Floating Point: Floating point numbers signify real numbers. This
-
data type is used to store numbers with a fraction part. They can be
represented in scientific notation where the lowercase or uppercase
letter 'e' or 'E' signifies the 10 ^ (th) power.
-
4. Complex Numbers: Complex numbers are pairs of real and
imaginary numbers. They take the form 'a + bj, where 'a' is the
-
float, 'b' is the real part of the complex number and j is the
imaginary part which represents the square root of -1.
-
5. None: This is a special data type with an unidentified value. It
-
signifies the absence of value in a situation, represented by
None. Python doesn't display anything when we give a command
to display the value of a variable containing value as None.
-
6. Sequence: A sequence is an ordered collection of items, indexed by
integers (both positive as well as negative). The three types of
sequence data types available in Python are Strings, Lists and Tuples,
-
-
7. Sets: Set is an unordered collection of values of any type with no
duplicate entry, enclosed within curly braces {}. It is mutable, for
E 3
-
O
Eg : x=20
print(x)
type(x)
int
& x=”Welcome” stries
=
type(x)
7 .
5
Operators 15% 1 =
1 %T
O -
O
O
O
O
O -
-
INPUT AND OYTPUT FUNCTIONS
Eg: # ⑤ s
a number and returns the numeric result (int or float as the case may be). If
the given argument is not a string or if it cannot be evaluated as a number,
then eval() results in an error. For example, eval (6*6) returns 36.
-
-
print() : print() is a function which is used to display the specified content on
the screen. It converts the argument into string before displaying on the
screen. The content (called argument) is specified within the parentheses.
print function without any arguments will simply jump to the next line.
Type conversion
Explicit conversion, also called type casting, happens when data type
conversion takes place deliberately, i.e., the programmer forces it in the
program. The general form of an explicit data type conversion is:
new_data_type (expression)
-
-
l=int(input(“Enter the length of rectangle”))
b=int(input(“Enter the breadth of rectangle”))
a= l*b
print(“Area is”,a)
Selection Statements -
1. If statement
If condition: -
-
statement(s) -
Eg: a=5 -
-
b=6
if(a>b):
-
2
print(“Large”,a)
2. If - else -
If condition: -
Statement(s) age : 20
else:
u
statement(s)
Is
Eg: if (age>=18)
-
print(“Eligible for -
vote”)
else:
print(“Not eligible for vote”)
If-elif-else
if condition:
↑
statement(s) -
elif condition:
statement(s)
elif condition:
statement (s)
else:
statement (s)
-
Iteration/Looping Statements
fur X In Fonts :
point(x)
For loop
Syntax of for loop
Em
parameter.
~
range(start,stop,step) -
-
Eg: range(0,30,5)
range
(12)
range (1 ,
10 -
While loop
while <test_expression>:
Body of while
else: # optional
Body of else
Eg: i=1
While i<=5:
print(i)
Strings
Eg:
'hello' is the same as "hello".
To"-
String Operation a =
"2"
+ - Concatination - b = "" =
-
* - Repetition
point (a b)
+
in/not in - membership -
[:] -Range(start,stop,[step]) -
--
e
[] - Slice[n:m]
-
a =
"2 "hello'
a =
* -
Syntax
[list_name]=[item1,item2,item3….,itemn]
Eg: L1=[10,20,30,40]
Built-in functions in List
len(list)
max(list)
min(list)
list(seq)
sum(list)
a =
, =
F5s-2-1
-
40 (a[B) & -
-
print(tup[0])
print(tup[1:3])
Dictionary
①
a -
2
Sri-mommy
0-9
-
a =
"Heio"
0123(
Ion(a)
115
range (0, Ion(a)]
U