IT 109 Midterm Concepts
What will be the outcome of the following code? >>> numbers = ['1','2','3'] >>> '+'.join(numbers) 5 6 '1+2+3' '1+2'
'1+2+3'
What will be the outcome of the following code? >>> str(10-5) '5' 5 5.0 Error
'5'
What is the outcome of the following concatenation operation? >>> 'HELLO' + 'WORLD' 'HELLO WORLD' 'HELLOWORLD' 'HELLO\nWORLD' 'HELLO+WORLD'
'HELLOWORLD'
Which of the following is a valid string type in python? name 'IT109' 12 5.0
'IT109'
How to obtain the sequence 'LIND' from word 'PALINDROME'? 'PALINDROME'[2:5] 'PALINDROME'[1:6] 'PALINDROME'[2:6] 'PALINDROME'[1:5]
'PALINDROME'[2:6]
What will be the outcome of the following code? >>> line = 'This is a test\n' >>> line.strip('\n') 'This is a test' 'This is a test\n' '\nThis is a test' All of the above
'This is a test'
What is the outcome of the following code? words = ['jazz', 'rock', 'country'] for i in range(len(words)): print(words[i]) 'jazz', 'rock', 'country' 0, 1, 2 'jazz', 'rock' 1,2,3
'jazz', 'rock', 'country'
What will be the index of item 'list' in the following list? words = ['This', 'is', 'a', 'list'] -1 0 1 None of the above
-1
What is the index position of 10 in the tuple (10, 20, 30)? -1 -2 -3 -4
-3
What is the outcome of the following code? for i in range(10): print(i,end = ',') 1,2,3,4... 10 0,1,2,3,4...10 0,1,2,3...9 0,1,2,3, ... 11
0,1,2,3,...9
What will be the outcome of the following code? i = 0 while i < 5: print(i) i += 1 0,1,2,3,4,5 0,1,2,3,4 0,1,2,3 0,1,2
0,1,2,3,4
Which of the following is NOT an arithmetic operator? 1.== 2.% 3.* 4.//
1. ==
What is the outcome of the following code? for i in range(2, 10, 2): print(i, end = ',') 2,3,4,... 10 2,4,6,...10 2,4,6,8 1,2,3,4,...100
2,4,6,8
What is the outcome? for x in range(20, 10, -1): print(x) 20, 10 20, 19, 18 ... 11 20, 18, 16, ... 10 20, 19, 18 ... 10
20, 19, 18 ... 11
Which of the following is an example of comparison operator? 1.== 2.>= 3.< 4.All of the above
4. all
What is the resolution of the following expression? 5 + 5 %2 6 7 0 1
6
What is the length of the following string? '1234%67*' 5 6 7 8
8 (COUNT FROM 1, dont forget * at end)
string
A sequence of characters, immutable (always in quotes)
What is the resolution of the following expression? True and False True False 1 0
False (AND is only T if both T)
Which of the following is true about index error? Index error is only for list. Index error means index does not exist. index error only exists for strings. Index error does not exist
Index error means index does not exist.
Which of the following is a False statement? Keywords are reserved words. Keywords are functions and exceptions Built-ins are functions and exceptions User-defined names are created by programmers.
Keywords are functions and exceptions
What will be the outcome of the code? if 1!=2: print('Label') elif 2!=1: print('Button') else: print('Entry') Label Button Entry Label and then Button
Label
What's the outcome of the following code? if 1 > 10: print('Button') elif 10 != 9: print ('Label') elif 2 > 6: print('Entry') else: print('Radio Button') Button Label Entry Radio Button
Label
What is the outcome of the following code? s = 'HELLO' for i in range(len(s)-1, - 1, -1): print(s[i]) HELLO OLLEH OLLEHOLLEH HELL
OLLEH
What is the outcome of the following code? for item in 'PYTHON': print(item, end = '-') PYTHON P-Y-T-H-O-N- P-Y-T-H-O- 0,1,2,3,4,5
P-Y-T-H-O-N-
What is the resolution of the following boolean expression? False and True or True True False 1 0
True
What will be the resolution of following expression? 10 >= 10 True False None Error
True
Which of the following statement is true? Variables are reserved memory location Values can be divided further to perform some analysis 5 and '123' can be examples of variables All of the above
Variables are reserved memory location
What will be the content of numbers at the end of the following code? >>> numbers = [10, 20, -100, 1] >>> numbers.append(100) [100, 10, 20, -100, 1] [10, 20, -100, 1, 100] [10, 20, -100, 1] None of the above
[10, 20, -100, 1, 100]
What will be the content of l2 at the end of the following code? >>> l1 = [10, 20] >>> l2 = [2, 3] >>> l2.extend(l1) [10, 20] [2,3] [2,3,10,20] [10, 20, 2, 3]
[2,3,10,20]
Which of the following are different identifiers in python? Keywords Built-ins User-defined All of the above
all of the above
Which of the following is true? lstrip() removes a leading character from a string rstrip() removes a trailing character from a string split() splits a string by delimiter and returns a list All of the above
all of the above
Tuple
an ordered container which is immutable ( tuple of strings:('one', 'two', 'three') | tuple of boolean: (True, False, False))
Which of the following is NOT a python data type? int float str double
double
Which of the following is right for loop syntax where <sequence> is a valid python sequence? for x in <sequence>: for x is <sequence> for x is <sequence>: None of the above
for x in <sequence>:
Which of the following is not a sequence in python? string list tuple int
int (sequence = works as a container)
Which of the following is not an immutable sequence? string tuple list None of the above
list is not immutable
Which one is the correct syntax to print a message? print('How are you? ') print {'How are you? '} print ('How are you? None of the above
print('How are you? ')
while loop
repeats code based on a condition
for loop
repeats part of a program based on a sequence
What would be the correct outcome of following code? >>> type('1.23') int float str boolean
str (bc quotes!)
What is the data type of variable 'number'? >>> number = input('Enter a valid number: ') Enter a valid number: 12 (user input) int float boolean string
string
input() converts everything to a
string
list vs tuple
syntax of tuples parentheses () syntax of lists square brackets [] (Lists has variable length, tuple has fixed length. List has mutable nature, tuple has immutable nature. List has more functionality than the tuple)
immutable
unchangeable
Which of the following is an invalid variable name? first_name x!y first_name1 xy
x!y