Deck 1: Basic Python Programming

Full screen (f)
exit full mode
Question
In Python, _MyVar15 is a valid variable name.
Use Space or
up arrow
down arrow
to flip the card.
Question
Strings are mutable objects, which means you can replace their contents.
Question
In Python, a variable containing the value 5 will evaluate as true if used with the and logical operator.
Question
The print function outputs a newline by default before its arguments are printed.
Question
If you print the string "Hello, it is a very \nice day", there will be two lines of output.
Question
Strings are compared using ASCII ordering.
Question
A docstring is another term for a Python variable that holds a string constant.
Question
The keywords True and False are floating point values.
Question
It is good practice to import all names from a module using the * operator.
Question
Use the comparison operator != to check if one value is not equal to another value.
Question
You can use the # symbol to create a multiline comment.
Question
Python programs require two or more modules.
Question
The keyword while means the same thing as While in Python.
Question
To make your program more secure, use obscure variable names such as xz14dEEa .
Question
Indenting code that should be executed when an if statement evaluates as true makes your program easier to read, but the indentation is not necessary.
Question
The while statement uses the syntax while : and is the preferred control statement to iterate over a definite range of sequences.
Question
Standard functions and Python's library functions check the types of their arguments when the function is called.
Question
The input function returns a numeric value by default.
Question
You can use the slice operator to obtain a substring from a string.
Question
The main python module contains the starting point of execution.
Question
To create an end-of-line comment, which symbol do you use to begin the comment?

A) #
B) *
C) /
D) @
Question
With what character does the print function terminate its output by default?

A) newline
B) null
C) period
D) space
Question
A list mutator is a method used to modify the contents of a list.
Question
The expression primes = (2, 3, 5, 7, 11) creates a list named primes.
Question
What can you use a docstring for?

A) to hold the name of a document file
B) to create a large string variable
C) to hold data of type string
D) to create a multiline comment
Question
What keywords does Python use for Boolean values?

A) Yes, No
B) On, Off
C) True, False
D) Set, Unset
Question
Which statement allows a programmer to run a module as a standalone program or import it from the shell?

A) do _module(main)
B) while main != _module
C) if self == "main()":
D) if __name__ == "__main__":
Question
Which statement is true about Python syntax?

A) a code block must begin with a left brace
B) each code statement must end with a semicolon
C) white space is ignored
D) blocks of code are indicated by indentation
Question
What keyword is used to make a multiway if statement?

A) else
B) elif
C) then
D) elseif
Question
A literal representation of a list is made using parentheses to enclose items separated by commas.
Question
A tuple is an immutable sequence of items and does not have mutator methods.
Question
What symbol is used to insert a tab in a string?

A) \t
B) [ TAB ]
C) / t
D) @ tab
Question
Which comparison operation returns True if variable x is not equal to variable y?

A) x .ne. y
B) x neq y
C) x <> y
D) x != y
Question
A dictionary object contains zero or more entries where each entry associates a unique key with a value.
Question
What is the output of the following code?
Sum = 0
For value in range(1,4):
If value == 2:
Sum = sum**2
Sum += value
Print(sum)

A) 6
B) 12
C) 8
D) 16
Question
Assume x is equal to 5 and y is equal to 0. Which comparison operation returns True?

A) x == y or y
B) y < 5 and y
C) (x > y) and x
D) x > 0 and None
Question
What is the output of the following code? sum = 0
Value = 3
While value <= 5:
Sum += value
Value += 1
Print(sum)

A) 15
B) 10
C) 12
D) 18
Question
What is the name of the function that contains the starting point of program execution?

A) start
B) main
C) begin
D) enter
Question
What is the output of the following code?
Sum = 0
For value in range(1,4):
Sum += value
Print(sum)

A) 5
B) 10
C) 4
D) 6
Question
Which of the following is true about Python keywords?

A) they can begin with a number, letter, or hyphen
B) they are case sensitive
C) they are written in uppercase
D) they can be a maximum of 6 characters long
Question
Which of the following statements creates a tuple containing four items?

A) t = [ 1: 2: 3: 4 ]
B) t = {1, 2, 3, 4}
C) t =t = < 1; 2; 3; 4 >
D) t = (1, 2, 3, 4)
Question
What is the value of string1 after the following statement is executed?
String1 = "hello"[ :3 ] + "python"[ 0 ]

A) lpython
B) llo
C) help
D) lop
Question
Select the answer that should be used to replace the missing code in the following statements. myList = list()
FileObj = open("myfile.dat", "rb")
While True:
Try:
Item = pickle.load(fileObj)
MyList.append(item)
< missing code >
FileObj.close()
Break
Print(myList)

A) if EOF:
B) elif Error:
C) except EOFError:
D) else while TRUE:
Question
In a class definition, what type of method uses the values of the object's instance variables without changing them?

A) constructor
B) accessor
C) instance
D) mutator
Question
What is the last line of the output when the following code is executed?
X = 2
For exp in range (5):
Print ("%2d.0" % x**exp)

A) 8.0
B) 16
C) 32
D) 16.0
Question
What is the value of z after the following code is run?
Y = 0
Z = 0
For x in range(5,8):
Z = max(x, y)
Y = y + x

A) 18
B) 11
C) 7
D) 13
Question
What are the values of variables x, y, and z after the following code is run?
Y = 0
Z = 0
For x in range(5,7):
If y > z:
Z, y = y, z
Y = y + x;

A) x == 7, y == 11, z == 6
B) x == 6, y == 6, z == 5
C) x = 6, y == 5, z == 6
D) x == 7, y == 12, z == 5
Question
How do you describe a function that calls itself?

A) self_calling function
B) iterative function
C) derivative function
D) recursive function
Question
What is the value of newList after the following code is executed?
NewList = [ "George", "John", "Thomas", "James" ]
NewList.pop()
NewList.append("Andrew")

A) [ "George", "John", "Thomas", "James", "Andrew" ]
B) [ "George", "John", "Thomas", "Andrew" ]
C) [ "Andrew", "John", "Thomas", "James" ]
D) [ "Andrew", "George", "John", "Thomas", "James" ]
Question
What is the last line of output of the following code?
Pres = {1:"Washington", 16:"Lincoln", 35: "Kennedy", 40:"Reagan"}
For nth in pres:
Print("%2d:" % nth,pres[ nth ])

A) 35: Kennedy
B) 40: Reagan
C) 03: Kennedy
D) 04: Reagan
Question
Which of the following correctly defines a function named myFunc?

A) def myFunc():
B) func myfunc:
C) myfunc()#
D) int myFunc:
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/51
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 1: Basic Python Programming
1
In Python, _MyVar15 is a valid variable name.
True
2
Strings are mutable objects, which means you can replace their contents.
False
3
In Python, a variable containing the value 5 will evaluate as true if used with the and logical operator.
True
4
The print function outputs a newline by default before its arguments are printed.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
5
If you print the string "Hello, it is a very \nice day", there will be two lines of output.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
6
Strings are compared using ASCII ordering.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
7
A docstring is another term for a Python variable that holds a string constant.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
8
The keywords True and False are floating point values.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
9
It is good practice to import all names from a module using the * operator.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
10
Use the comparison operator != to check if one value is not equal to another value.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
11
You can use the # symbol to create a multiline comment.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
12
Python programs require two or more modules.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
13
The keyword while means the same thing as While in Python.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
14
To make your program more secure, use obscure variable names such as xz14dEEa .
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
15
Indenting code that should be executed when an if statement evaluates as true makes your program easier to read, but the indentation is not necessary.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
16
The while statement uses the syntax while : and is the preferred control statement to iterate over a definite range of sequences.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
17
Standard functions and Python's library functions check the types of their arguments when the function is called.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
18
The input function returns a numeric value by default.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
19
You can use the slice operator to obtain a substring from a string.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
20
The main python module contains the starting point of execution.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
21
To create an end-of-line comment, which symbol do you use to begin the comment?

A) #
B) *
C) /
D) @
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
22
With what character does the print function terminate its output by default?

A) newline
B) null
C) period
D) space
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
23
A list mutator is a method used to modify the contents of a list.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
24
The expression primes = (2, 3, 5, 7, 11) creates a list named primes.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
25
What can you use a docstring for?

A) to hold the name of a document file
B) to create a large string variable
C) to hold data of type string
D) to create a multiline comment
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
26
What keywords does Python use for Boolean values?

A) Yes, No
B) On, Off
C) True, False
D) Set, Unset
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
27
Which statement allows a programmer to run a module as a standalone program or import it from the shell?

A) do _module(main)
B) while main != _module
C) if self == "main()":
D) if __name__ == "__main__":
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
28
Which statement is true about Python syntax?

A) a code block must begin with a left brace
B) each code statement must end with a semicolon
C) white space is ignored
D) blocks of code are indicated by indentation
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
29
What keyword is used to make a multiway if statement?

A) else
B) elif
C) then
D) elseif
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
30
A literal representation of a list is made using parentheses to enclose items separated by commas.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
31
A tuple is an immutable sequence of items and does not have mutator methods.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
32
What symbol is used to insert a tab in a string?

A) \t
B) [ TAB ]
C) / t
D) @ tab
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
33
Which comparison operation returns True if variable x is not equal to variable y?

A) x .ne. y
B) x neq y
C) x <> y
D) x != y
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
34
A dictionary object contains zero or more entries where each entry associates a unique key with a value.
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
35
What is the output of the following code?
Sum = 0
For value in range(1,4):
If value == 2:
Sum = sum**2
Sum += value
Print(sum)

A) 6
B) 12
C) 8
D) 16
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
36
Assume x is equal to 5 and y is equal to 0. Which comparison operation returns True?

A) x == y or y
B) y < 5 and y
C) (x > y) and x
D) x > 0 and None
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
37
What is the output of the following code? sum = 0
Value = 3
While value <= 5:
Sum += value
Value += 1
Print(sum)

A) 15
B) 10
C) 12
D) 18
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
38
What is the name of the function that contains the starting point of program execution?

A) start
B) main
C) begin
D) enter
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
39
What is the output of the following code?
Sum = 0
For value in range(1,4):
Sum += value
Print(sum)

A) 5
B) 10
C) 4
D) 6
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is true about Python keywords?

A) they can begin with a number, letter, or hyphen
B) they are case sensitive
C) they are written in uppercase
D) they can be a maximum of 6 characters long
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following statements creates a tuple containing four items?

A) t = [ 1: 2: 3: 4 ]
B) t = {1, 2, 3, 4}
C) t =t = < 1; 2; 3; 4 >
D) t = (1, 2, 3, 4)
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
42
What is the value of string1 after the following statement is executed?
String1 = "hello"[ :3 ] + "python"[ 0 ]

A) lpython
B) llo
C) help
D) lop
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
43
Select the answer that should be used to replace the missing code in the following statements. myList = list()
FileObj = open("myfile.dat", "rb")
While True:
Try:
Item = pickle.load(fileObj)
MyList.append(item)
< missing code >
FileObj.close()
Break
Print(myList)

A) if EOF:
B) elif Error:
C) except EOFError:
D) else while TRUE:
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
44
In a class definition, what type of method uses the values of the object's instance variables without changing them?

A) constructor
B) accessor
C) instance
D) mutator
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
45
What is the last line of the output when the following code is executed?
X = 2
For exp in range (5):
Print ("%2d.0" % x**exp)

A) 8.0
B) 16
C) 32
D) 16.0
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
46
What is the value of z after the following code is run?
Y = 0
Z = 0
For x in range(5,8):
Z = max(x, y)
Y = y + x

A) 18
B) 11
C) 7
D) 13
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
47
What are the values of variables x, y, and z after the following code is run?
Y = 0
Z = 0
For x in range(5,7):
If y > z:
Z, y = y, z
Y = y + x;

A) x == 7, y == 11, z == 6
B) x == 6, y == 6, z == 5
C) x = 6, y == 5, z == 6
D) x == 7, y == 12, z == 5
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
48
How do you describe a function that calls itself?

A) self_calling function
B) iterative function
C) derivative function
D) recursive function
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
49
What is the value of newList after the following code is executed?
NewList = [ "George", "John", "Thomas", "James" ]
NewList.pop()
NewList.append("Andrew")

A) [ "George", "John", "Thomas", "James", "Andrew" ]
B) [ "George", "John", "Thomas", "Andrew" ]
C) [ "Andrew", "John", "Thomas", "James" ]
D) [ "Andrew", "George", "John", "Thomas", "James" ]
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
50
What is the last line of output of the following code?
Pres = {1:"Washington", 16:"Lincoln", 35: "Kennedy", 40:"Reagan"}
For nth in pres:
Print("%2d:" % nth,pres[ nth ])

A) 35: Kennedy
B) 40: Reagan
C) 03: Kennedy
D) 04: Reagan
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following correctly defines a function named myFunc?

A) def myFunc():
B) func myfunc:
C) myfunc()#
D) int myFunc:
Unlock Deck
Unlock for access to all 51 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 51 flashcards in this deck.