DP2 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What will be the output of the following code snippet? class Sales: def __init__(self,id): self.id= id id=100 val= Sales(123) print(val.id)

123

Evaluate the operation below and select the correct result: MyNum=11//3 print(MyNum)

3

Which of the following result is correct? tup= tuple("this is us") print (tup) index= tup.index("s", 3, 9) print(index)

3

What is the response from the editor when the following is entered: print(type(3.14))

<class 'float'>

What is the decorator symbol to be used for creating static method in python class?

@

What is the output for the following code? classes={'Kaleta':'IT3140','Zhang':'IT3131','Rasnick':'IT2431'} a=classes.items() a.append('IT2333') print(a)

AttributeError: 'dict_items' object has no attribute 'append'

What is the meaning for \b in regular expression?

Boundary

Because self is the default argument for constructor member functions, it does not have to be included in the definition:

False

What is the output of the following code? class test: a="Hello World" def __init__(self,a): self.a=a def display(self): print(self.a) obj=test('Hi there') obj.display()

Hi there

Which of the following results is correct for the print statement? a='fox' b='dog' c='cat' print("I saw {2} is catching {0} and {1}".format(a,b,c))

I saw cat is catching fox and dog

Which is the result of the following code? import re class Employee: def __init__(self,first,last): self.fname=first self.lname=last class Developer(Employee): pass dev_1=Developer("John","Smith") print(dev_1.fname)

John

Which of the following result is correct? lst=['b','a','d','c','e'] sort(lst) print(lst)

NameError: name 'sort' is not defined

What is the output for the following code? import re text= 'c:\downloads\app' pos=re.search('\d',text) print(pos)

None

What is the output of the following code? lst=[2,4,6] lst= lst.append(8) print(lst)

None

What is a class?

The abstract characteristics of an object, including the attributes and behaviors.

Given the following class tree, which is correct if you print out the result for 12.x ?

The value of x in C1 because it is close to 12.

According to the textbook and slides we used, a cookie is a class and the cookie cutter is an instance of the cookie class.

True

Which of the following statement is correct? t=('a','b','c','d','e') t=('A')+t[1:] print(t)

TypeError: can only concatenate str (not "tuple") to str

What is the output for the following code? dct={'a':2,'b':1,'c':3} for k,v in dct: print(k,end='') print(v,end='')

ValueError: not enough values to unpack (expected 2, got 1)

What is the output for the following code? dct={'a':2,'b':1,'c':3} for k,v in dct: print(k,end='') print(v,end='')

ValueError: not enough values to unpack (expected 2, got 1)

Which of the following result is correct? n1, n2=4,8,3 print(n1,n2)

ValueError: too many values to unpack (expected 2)

What is the meaning of the symbol * as a quantifier in Regular Expression?

Zero or more times.

What is the output for the following code? dct={'a':2,'b':1,'c':3} print(sorted(dct))

['a', 'b', 'c']

What is the output for the following code? import re text=""" Y-DSPAM-Confidence: 0.8475 100 Z-DSPAM-Probability: 0.0001 102 """ print(re.findall('(\S*): ([0-9.]+)[0-9.]+',text))

[('Y-DSPAM-Confidence', '0.847'), ('Z-DSPAM-Probability', '0.000')]

Which of the following would be the regular expression symbol for starting the string?

^ symbol

What is the output for the following code? dct={'a':1,'b':2,'c':3} for p in dct: print(p,end='')

abc

Which of the following is result for the following code? dict={'item1':'a','item4':'b','item3':'c','item2':'d','item5':'e'} x=dict.get('item0','b') print(x)

b

Which is the result for the following code? for i in['a','b']: for j in ['c','d']: print(j,end='') print(i,end='')

cdacdb

Which line is deconstructor? class SleepSheep: x=0 def __init__(self): print("Count on us to put you to sleep") def sleep(self): self.x=self.x+1 print('Sheep',self.x) def __del__(self): print('Sleeping person after', self.x,'sheep')

def __del__(self):

In this class given below, which line is the constructor? class SleepSheep: x=0 def __init__(self): print('Count on us to put you to sleep') def sleep(self): self.x=self.x+1 print('Sheep',self.x) def __del__(self): print("Sleeping person after",self.x,'sheep')

def __init__(self):

What is the data type of dct.values()?

dict_values

Which of the following code segments will run, assuming there ___ the data file?

fhand= open('mbox-short.txt') count=0 for line in fhand: if line.startswith('From:'): print(line)

Given the following class, which one is an instance argument? import re class Employee: raise_rate=1.04 def __init__(self,first,pay): self.fname=first self.pay=pay

first

What is the output for the following code? s='hello' s.replace('ll','tt') print(s)

hello

Which one is the operator that can be used to check if a key exists in a dictionary?

in

Given the following class,which one is an instance attribute? import re class Employee: raise_rate= 1 @4 def __init__(self,first,pay): self.fname=first self.salary= pay

instance variable is fname , salary

What is the output for the following code? from copy import copy tup=("Hello",5,[ ],True) tup_copy=copy(tup) tup[2].append(1) print(tup_copy)

('Hello', 5, [1], True)

What is the output for the following code? s='hello world' tup=tuple(s) print(tup)

('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd')

What is the output of the following code? num=1,2,3,4,5 print(num[::-2])

(5, 3, 1)

Which of the output of the following program? class Employee: raise_rate=1.04 def __init__(self,first,pay): self.fname=first self.salary=pay emp_1=Employee('John',5000) emp_2=Employee('Alice',60000) emp_1.raise_rate=1.1 print(Employee.raise_rate) print(emp_2.raise_rate)

1.04 1.04

What is the output of the following code? a=1,2,3 b=4 c=a+b print(c)

Error: Cant concatenate a tuple.

N/A

it will run an infinite loop

The first argument of every method is a reference to the current instance of the class, referred to as:

self

Which one is the first argument to create a class method?

self

Which of the following result is correct? eng2sp={'one':'uno','two':'dos','three':'tres'} eng2sp['one']='Yi' print(eng2sp)

{'one': 'Yi', 'two': 'dos', 'three': 'tres'}

What is the output for the following code? dct={'one':'uno','two':'dos','three':'tres'} dct.update({'two':2}) print(dct)

{'one': 'uno', 'two': 2, 'three': 'tres'}


Set pelajaran terkait

Biology: Human Anatomy and Physiology

View Set

Fundamentals of Financial Planning Questions

View Set

Microbiology Chapter 6 LearnSmart

View Set

Equations with variables on both sides (including special solutions), Literal Equations

View Set

Patient Protection and Affordable Care Act (PPACA) - Section 14

View Set

EQE Unit: 1, 16, 4, 2 [Ch 1, 2, 10, 3, 4]

View Set

Chapter 61: Caring for Clients Requiring Orthopedic Treatment

View Set