Quiz 3 - Class and Functions

Ace your homework & exams now with Quizwiz!

What is the output of the following code? class test: def __init__(self,a="Hello World"): self.a=a def display(self): print(self.a) obj=test() obj.display() The program has an error because constructor can't have default arguments Nothing is displayed "Hello World" is displayed The program has an error display function doesn't have parameters

"Hello World" is displayed

What is the output of the following code? class change: def __init__(self, x, y, z): self.a = x + y + z x = change(1,2,3) y = getattr(x, 'a') setattr(x, 'a', y+1) print(x.a) 6 7 Error 0

7

Regarding class variables, what statement is accurate? A class variable is only visible to a single instance of a class. A class variable is visible only to methods inside a class. A class variable is visible to all instances of a class, but can vary from instance to instance. A class variable is visible to all instances of a class, and does not vary from instance to instance.

A class variable is visible to all instances of a class, and does not vary from instance to instance.

1. _____ represents an entity in the real world with its identity and behavior. A method An object A class An operator

An object

A function call expresses the idea of a process to the programmer, forcing him or her to wade through the complex code that realizes that idea. I True False

False

In Python, = means equals, whereas == means assignment. True False

False

Inheritance allows several different classes to use the same general method names. True False

False

The amount of memory needed for a loop grows with the size of the problem's data set. True False

False

The scope of an instance variable is the entire module. True False

False

The simplest form of selection is the if-else statement. Incorrect Response True False

False

The statements within a while loop can execute one or more times. True False

False

Given the following statement: "%4d" % var1, which of the following is accurate? The variable var1 must be an integer value. The variable var1 must be a string value. The variable var1 will be in octal format. The variable var1 will be formatted regardless of type.

The variable var1 must be an integer value

A method automatically returns the value None when it includes no return statement. True False

True

A method reference always uses an object, which can be denoted by a string followed by a dot and the method name. True False

True

Although Python is considered an object-oriented language, its syntax does not enforce data encapsulation. True False

True

An abstraction hides detail and thus allows a person to view many things as just one thing. True False

True

Which of the following statements are accurate? (Choose two.) Parameters for a function receive values when they are declared. When module variables are introduced in a program, they are immediately given a value. A nested variable can assign value to a variable outside of its scope. Temporary values receive their values as soon as they are introduced.

When module variables are introduced in a program, they are immediately given a value. Temporary values receive their values as soon as they are introduced.

What method is known as a class's constructor, because it is run automatically when a user instantiates the class? __start__ __build__ __main__ __init__

__init__

1. Which of the following functions is a built-in function in python? a) seed() b) sqrt() c) factorial() d) print() seed() sqrt() factorial() print()

print()

For each call of a function, the Python virtual machine must allocate a small chunk of memory on the call stack, which is known by what term? stack chunk stack frame data nibble memory slice

stack frame


Related study sets

Phlebotomy Essentials 6th edition. ALL quizzes, ALL ch. tests, GRADED work, NOT guesses. PLUS, the FULL NAHP study guide

View Set

Exam Review Questions- Treatment and Rehabilitation

View Set

Ch 64: Neurologic Infections PrepU

View Set

National Agricultural Technology Quiz - LANDON NOFIRE

View Set

Personal Finance Retirement Accounts

View Set

Chapter 10 - Small Business Entrepreneurs

View Set

Hesi Edition 6 Practice Q's for PEDS

View Set

Chapter 1 | Introduction to Cognitive Psychology

View Set