Python for Data Science
Consider the function add, what is the result of calling the following Add('1','1') (look closely at the return statement ) def Add(x,y): z=y+x return(y)
'1'
What is the output of the following few lines of code ? A=['1','2','3'] for a in A: print(2*a)
'11' '22' '33'
The variables A='1' and B='2' ,what is the result of the operation A+B?
'12'
Consider the string A='1234567', what is the result of the following operation: A[1::2]
'246'
What does the following loop print? for n in range(3): print(n+1)
1 2 3
Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation A[0][1]:
12
how many iterations are performed in the following loop? for n in range(3): print(n)
3
Consider the string Name="Michael Jackson" , what is the result of the following operation Name.find('el')
5
What is the result of the following operation 3+2*2?
7
Consider the variable F="You are wrong", Convert the values in the variable F to uppercase?
F.upper()
What is the output of the following lines of code: x="Go" if(x!="Go"): print('Stop') else: print('Go ') print('Mike')
Go Mike
What is the output of the following lines of code: x="Go" if(x=="Go"): print('Go ') else: print('Stop') print('Mike')
Go Mike
What is the result of the print("Hello\nWorld!") statement?
Hello World!
Consider the class Points, what are the data attributes: class Points(object): def __init__(self,x,y): self.x=x self.y=y def print_point(self): print('x=',self.x,'y=',self.y)
self.x.self.y
What is the result of the following operation int(3.2)?
3
Concatenate the following lists A=[1,'a'] and B=[2,1,'d']:
A+B
How do you cast the list 'A' to the set 'a'?
a=set(A)
What is the type of the following variable: True?
bool
What is the output of executing the following statement: # print('Hello World!')?
There is no output as it is a comment. (A # is always a comment)
What is the result of the following operation '1,2,3,4'.split(',')
['1','2','3','4']
Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation A[1]:
[21,22]
Enter the code to convert the number 1 to a Boolean.
bool(1)
What is the type of the following: int(1.0)?
int
Consider the following line of code: with open(example1,"r") as file1: What mode is the file object in?
read
What is the result of running the following lines of code ? class Points(object): def __init__(self,x,y): self.x=x self.y=y def print_point(self): print('x=',self.x,' y=',self.y) p1=Points(1,2) p1.print_point()
x=1 y=2
What is the result of running the following lines of code ? class Points(object): def __init__(self,x,y): self.x=x self.y=y def print_point(self): print('x=',self.x,' y=',self.y) p2=Points(1,2) p2.x=2 p2.print_point()
x=2 y=2
Consider the Set: V={'A','B','C' }, what is the result of V.add('C')?
{'A','B','C'}
Consider the Set: V={'A','B'}, what is the result of V.add('C')?
{'A','B','C'}