Python Exam

Ace your homework & exams now with Quizwiz!

Which of the following statements create a dictionary? a. d = {} b. d = {"john":40, "peter":45} c. d = {40:"john", 45:"peter"} d. All of the mentioned

all of the mentioned

Which of the following is an invalid statement? a. abc = 1,000,000 b. a b c = 1000 2000 3000 c. a,b,c = 1, 2, 3 d. a_b_c = 4,000,000

b. a b c = 1000 2000 3000

Which of the following statement terminates the loop statement and transfers execution to the statement immediately following the loop? a. continue b. break c. exit d. pass

b. break

Which of the following is an invalid variable? a. my_string b. __a c. 1st_string d. foo_24

c. 1st_string

Which of the following is correct about Python? a. Python is a high-level, interpreted, interactive and object-oriented scripting language. b. Python is designed to be highly readable. c. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages. d. All of the above

d. All of the above.

All keywords in Python are in a. lower case b. UPPER CASE c. Capitalized d. None of the above

d. None of the above

Which of the following operator in python evaluates to true if it does not finds a variable in the specified sequence and false otherwise? a. ** b. // c. is d. not in

d. not in

Following set of commands are executed in shell, what will be the output? >>> str = "hello" >>> str[:2] >>>

he; because you are printing only the first two bytes of string.

The output of the following? print("Hello {name1} and {name2}".format(name1 = 'foo', name2 = 'bin')) gives you: Hello foo and bin Why?

Because the arguments are accessed by their names.

What is the output of the following code: x = ['ab', 'cd'] for i in x: -> i. upper() print(x)

['ab', 'cd']

What is the output of the following? x = 'abcd' for i in range(len(x)): -> print(i.upper()) a. a b c d b. 0 1 2 3 c. error d. 1 2 3 4

a. a b c d

What is the output of the following? string = "my name is x" for i in string: -> print(i, end = ", ") a. m, y, , n, a, m, e, , i, s, , x, b. m, y, , n, a, m, e, , i, s, , x c. my, name, is, x, d. error

a. m, y, , n, a, m, e, , i, s, , x,

Is Python case sensitive when dealing with identifiers? a. yes b. no c. it depends on context d. it depends on data type

a. yes

What is the output of the following? print('abcdef12'.replace('cd', '12')) a. abcdef12 b. ab12ef12 c. ab12efcd d. none of the above

b. ab12ef12

Which of the following functions reverses objects of lists in place? a. list.sort([func]) b. list.reverse() c. list.pop(obj=list[-1]) d. list.remove(obj)

b. list.reverse()

What is the output of the following? x = 2 for i in range(x): -> x += 1 -> print(x) a. 0 1 2 3 4 .... b. 0 1 c. 3 4 d. 0 1 2 3

c. 3 4

What is the output when the following code is executed? >>> print(r"\nhello") a. a new line and hello b. the letter r and then hello c. error d. \nhello

c. error

You have the following code: d = {"john":40, "peter":45} print(d["john"]) What type of data structure is 'd'? Also, what do you receive from the second line? (separate your answers by a single space)

d is a dictionary you receive the number 40 because "john":40

Which one of the following have the highest precedence in the expression? a. Exponential b. Addition c. Multiplication d. Parentheses

d. Parentheses

What is the output of the following? True = False while True: -> print(True) -> break a. True b. False c. None d. none of the above

d. none of the above

The following is displayed after a print() call: tom dick harry Select the function call that results in this output a. print("\ttom \tdick \tharry") b. print("\ttom \tdick \tharry") c. print(" tom dick harry") d. print("\ttom\n\tdick\n\tharry")

d. print("\ttom\n\tdick\n\tharry")

______________(str) is the function to run in the shell to find out details about how to use str() and the type of data it accepts and returns.

help

What is the output of the following? x = 'abcdef' i = "a" while i in x: -> print ('i', end = " ") and why?

i i i i i i i i ..... because, you are running a while loop, therefore until i is not found in x it will continue to run. "a" will always be found in the string of characters 'abcdef', therefore: i i i i i i i, will never end.

What method checks in a string that all characters are in uppercase?

string.isupper(), it will return true if all the character in the string are uppercase, and false if the string contains one or more non-uppercase characters.


Related study sets

Fundamentals Exam 1 (chapter 38 oxygenation & perfusion)

View Set

Police Administration - Chapter 11

View Set