Fundamentals of Python Final Study Guide

¡Supera tus tareas y exámenes ahora con Quizwiz!

Declaring a lass creates actual objects.

False

The For loop is limited to incrementing the value of the counter by 1

False

JSON stands for JavaScript ___ Notation

Object

The term ____, refers to the creation of reusable software objects that can be incorporated into multiple programs.

Object Oriented Programming

The Python keywords used to construct a loop to iterate through a list are ___ and __

for and in

All text strings must begin and end with double quotation marks

fase

The nested list undergoes shallow copy even when the list as a whole undergoes deep copy

False

Very rarely, you will write programs that use classes created by others.

False

When you add items to a dictionary they remain in the order in which you added them.

False

You can mix spaces and tabs when indenting in Python

False

You can use the Matplotlib.maps to create a geovisualizatio directly in Python.

False

You must have the word self when setting the properties of an object within the class

False

You must use the keyword self when setting the properties of an object within the class

False

___ are lines you place in your code that do not get executed but provide helpful information such as the name of the script

comments

What method do you call in an SQLite cursor object in Python to run an SQL command?

execute()

For loops cannot be nested inside one another

false

The best way to run Python is from the command line

fase

You need three sets of data to create a bubble chart

true

Using the following tuple, how would you print 'Wed'?: days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')

print(days[2])

Given the following list, what is the line of code you would use to output "Sally"?: friends = [ 'Joseph', 'Glenn', 'Sally' ]

print(friends[2])

A(n) ____ is any group of characters enclosed within either double or single quotation marks in Python

string

The delete)many() method allows us to delete many documents

True

The following code will produce an error: print("{0:2f}".format(53) + 35

True

The Python ____ function returns the total number of characters in a string

len

What is the iteration variable in the following code?: for letter in 'banana' print(letter)

letter

Input validation should be based on...

Whitelisting

Class names in a class definition are NOT followed by ____, as are function names in a function definition

()

Inheritance is the process of combining all of an object's attributes and methods into a single package.

False

Overriding means changing behavior of methods of subclass class methods in the parent or superclass

False

Pandas Series don't allow accessing individual elements through labels

False

Python only allows the minutes and seconds to be retrieved from time

False

Suppose that yo have the following code: num = 10 if num > 10: print(num) else: print(num+5)

False

The Series is a core data model whereas the Data Frame is a secondary model for Pandas

False

The datetime.time and the time.time() classes are used to do the same thing.

False

The datetime.time object is used in Python to work with dates

False

The delete_one() method lets us delete many documents

False

The detDate() method returns the specific month for a particular date.

False

What will end up in the variable a after this code is executed: a, b = "Hello", "World"

"Hello"

JSON elements are separated by the ___

, or comma

What does this code output?: astr = 'Hello Bob' istr = 0 try: istr = int(astr) except: istr = -1 print(istr)

-1

What is the "wild card" character in a regular expression (i.e., the character that matches any character?)

. or dot

Python scripts (files) have names that end with:

.py

How many times will the body of the following loop be executed? n = 0 while n > 0 : print 'Lather' print 'Rinse' print 'Dry off!'

0

Complete code to return the output: [19 2 13] import numpy as np x = np.array([19, 2, 13, 4]) print(x[______])

0:3

Consider the following code: num = 1 for i in [1, 2, 3, 4] : break num += 2 print(num) What will the value of num be after the loop has executed?

1

In the following code (numbers added) - which will be the last line of code to execute successfully? (1) astr = 'Hello Bob'(2) istr = int(astr)(3) print 'First', istr(4) astr = '123'(5) istr = int(astr)(6) print 'Second', istr

1

Consider the following code: class Clock(object): def __init__(self, time): self.time = time def print_time(self, time): print(time) clock = Clock('5:30') clock.print_time('10:30') What does the code print out?

10:30

What is the value of the following expression: 42%10

2

What is the output of the following python expression id x=345? print("{0:3.2f}".format(x))

345.00

What does the following Python Program output? x = '40' y = int(x) + 2 print(y)

42

What does the following Python program print out?: tot = 0 for i in [5, 4, 3, 2, 1] : tot = tot + 1 print (tot)

5

What does the following Python code print out?: a = [1, 2, 3] b = [4, 5, 6] c = a + b print(len(c))

6

All objects have predictable attributes because they are members of certain methods.

False

An object's attributes must be defined in the object's __init__ method

False

To perform a reverse sort of query results from a SELECT statement, add the ___ keyword after the name of the field by which you want to perform the sort.

DESC

Using the COUNT() aggregate function, you can eliminate duplicate values by using the keyword(s)___

DISTINCT

Backdoors should remain in software when it is placed into production, because they allow quick access to the core components, which is helpful for quick vulnerability patching

False

Consider the following code: import numpy as npa = np.array([1, 2]) b = np.array([3, 4, 5]) c = b[1:] print(b[a] is c) What does this print

False

A numpy array length may be edited after the array is created

False

A scatterplot is best used for time series data

False

What does the following Python program print out? str1 = "Hello"str 2 = 'there' bob = str1 + str2 print(bob)

Hellothere

Objects are also called

Instances

In the following SQL: cur.execute('SELECT count FROM Counts WHERE org = ? ', (org)) What is the purpose of the "?"

It is a placeholder for the contents of the "org" variable

To use JSON in your python application you must import ____

JSON

Complete the code below so the second statement will run: import _______ as npnp.array([19, 21, 15, 26])

NumPy

A ____ is a structured set of instructions and criteria for retrieving, adding, modifying, and deleting database information.

QUERY

Consider the following code class Spell(object): def __init__(self, incantation, name): self.name = name self.incantation = incantation def __str__(self): return self.name + ' ' + self.incantation + '\n' + self.getDescription() def getDescription(self): return 'No description' def execute(self): print(self.incantation) class Accio(Spell): def __init__(self): Spell.__init__(self, 'Accio', 'Summoning Charm') class Confundo(Spell): def __init__(self): Spell.__init__(self, 'Confundo', 'Confundus Charm') def getDescription(self): return 'Causes the victim to become confused and befuddled.' def studySpell(spell): print(spell) spell = Accio() spell.execute() studySpell(spell) studySpell(Confundo()) What are the parent class(ses)? Note the term "parent class" is interchangeable with the term "super class"

Spell

What would be the output of the following code be? import requests url = 'https://httpbin.org/' try: response = requests.get(url) # If the response was successful, no Exception will be raised response.raise_for_status() except Exception as err: print('Error occurred') else: print('Success!')

Success!

$in is a valid MongoDB query operator

True

A Pandas data frame is similar to Excel workbook

True

A database may contain one or more collections

True

Atlas can be run on any cloud service provider such as Azure, AWS, GCP, etc.

True

Both the now() or the today() class methods return the current local date and time

True

In Python 3, all strings are Unicode

True

Inheritance is the process of acquiring the traits of one's predecessors

True

Is the following piece of code correct? class A: def __init__(self,b): self.b=b def display(self): print(self.b) obj=A("Hello") del(obj)

True

MongoDB has a special data type called ObjectId for uniquely identifying documents

True

MongoDB is classified as a no SQL database

True

PyMongo supports the MongoDB aggregation framework and query language

True

Series and DataFrames are the 2 key data structures in Pandas

True

Software security is often a problem because most programmers aren't trained in information security, and most information security professional aren't programmers

True

Suppose that you have the following statements: if score >= 65: grade = "pass" else: grade = "fail"

True

The methods find() and find_one() both accept a query predicate

True

The two main structures that compose JSON are Arrays and Objects

True

There is no such thing as absolute security

True

This code will generate an AssertionError. def test_string(text): assert insinstance(text, str), "This is not a string" return str(text) test_string(453

True

With object-oriented programming, once you create an object, you can develop new objects that possess all the traits of the original object plus any new traits you desire

True

Your application performs logging queries after certain events. Timestamp, IP address, message content and type of action will be saved to a SQLite database. It is possible for an adversary to bypass this logging query by sending specifically crafted message.

True

The ___ keyword specifies the name of the table that needs to modified when updating records

UPDATE

You can filter which records to return from a database by using the ___ keyword

WHERE

Consider the following code: class Clock(object): def __init__(self, time): self.time = time def print_time(self): print(self.time) boston_clock = Clock('5:30') paris_clock = boston_clock paris_clock.time = '10:30' boston_clock.print_time()

What does the code print out 10:30 Are Boston_clock and Paris_clock different objects? no

The following code starts with the definition of a class Address. The class needs to have two attributes: number and streetName. Please add in the two lines of code that will create these attributes from the appropriate passed in parameters. class Address(object): def __init__(self, number, streetName): # Line 1: Creating a number attribute # Line 2: Creating a streetName attribute

What is the correct expression for #line 1 self.number = number What I the correct expression for #line 2 self.streetName = streetName

In a regular expression, ______ characters tell the computer or interpreter that the character that follows it has a special purpise

\

What Regular Expression matches one or more digits?

\d+ or [0-9]+

You are creating a line plot using the following code: a = [1, 2, 3, 4] b = [3, 9, 2, 6] plt.plot( a, b) plt.show() a) the values in a are mapped onto the horizontal axis b) The values in b are mapped onto the horizontal axis c) The values in a are mapped onto the vertical axis d) The values in b are mapped onto the vertical axis

a and d

Which method of cursor class is used to get the number of rows affected after any of the insert/update/delete database operation executed in Python? a) cursor.rowcount b) cursor.getaffectedcount c) cursor.rowscount d) No answer text provided

a)

Which of the following formats is not a numeric value data type?: a) "12" b) 11.5 c) 3 d) All of the choices are numeric

a)

Which of the following options correspond to matching a pattern zero or more times? a) * b) ? c) + d) [2]

a)

Which of the following are considered dangerous software errors? a) SQL injection b) Cross-site Scripting c) Classic buffer overflow d) JSON parsing e) Missing Authentication

a, b, c, e

To add an element to the end of a list, you need to run the ___ function

append

Which of the following are used for security surrounding API usage? a) Combination Code b) API key c) OAuth d) A physical key

b and c

Hakcers often gather a multitude of seemingly small, innocuous pieces of configuration about a site that, when combined, can help them attach a site. Which of the following error messages would NOT typically be considered safe to display to the user? a) A message that states that the system is down for maintenance and tells what time it is expected to be back up. E.g.:Our site is down. We're sorry for the inconvenience.We are doing maintenance on our servers.The site should be up by 11:00 PM PST. b) An error message that says there was an internal error message and displays the call stack to assist in debugging and reporting of the error.There was an internal error. Please send a copy-and-paste of this page to the sysadmin. c) An error message that says there was an internal error but does not provide any details to assist in debugging or reporting of the error. E.g.:There was an internal error. Please report this to the sysadmin. d) A message that says that there was an error logging in mentioning the username. E.g.:User "JoeUser" could not be logged in with the information you provided.

b)

What is it called when we make a logical error in a program? a) Error b) Bug c) Mistake d) Debug

b)

To print a stacked bar chart you type what:

bottom=means_xxxx

Asume brics is a Pandas DataFrame that looks like this: country population area capital B R I C S Which of the following are valid ways to access the column "area" in this data frame?

brics.area or brics["area"]

The user authorization must be renewed after;; a) A client logs in b) A short idle period (i.e. 30 seconds) c) Any privilege level change

c)

Which of the following is involved in the debugging process? a) Finding bugs b) Fixing bugs c) Both finding bugs and fixing them d) Clearing bugs

c)

An exception is caused by ____: a) A hardware problem b) A problem in the OS c) A run-time error d) A syntax error

c) A run-time error

The argument you pass to the Len() function is a literal string or string variable whose _____ you want to count

characters

In JSON, the an object must be enclosed in ___

curly braces

Which if the following is NOT an appropriate action/ attitude of keeping self awareness of information security? a) Treat it as your own responsibility to ensure software security b) Keep alert to security news & practices with the latest knowledge c) Consult other knowledgeable persons if in doubt d) It is not your concern if the hacking or virus outbreak did not occur in code you wrote

d

Which of the following is NOT an example of a visual represetation? a) graph b) picture c) movie d) table

d)

Which Python keyword indicates the start of a function definition?

def

Which data structure is most often used when counting the frequency of words in a document?

dictionary

What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false?

else

What is the iteration variable in the following Python code?: friends = ['Joseph', 'Glenn', 'Sally'] for friend in friends : print('Happy New Year:', friend) print('Done!')

friend

What Python function would you use if you wanted to prompt the use for a file name to open

input

What is the type of the return value of the re.findall() method?

list

In PyMongo, the ___ method display the list of databases

list_database_names()

Consider the following code: j = 3 while j < 10 : print("J has value ", j) After how many times does the loop stop?

never

Complete the code to find the median of x: # Find the median of x import numpy as np x = np.array([4.19, 3.65, 2.93]) print(_________(x))

np.median

Sending arguments to the parameters of a called function is _____ arguments

passing

The __ function reads the contents of a text file that stores the whole file as a single string

read or read()

Consider the following code: response = requests.get('https://api.github.com') The response of a request often has some valuable information, known as a payload, in the request body. Which of the following methods and properties are defined correctly to view the content of a response? Select all that apply:

response.text returns the response content as a string object. response.content returns the response content as a bytes object.

A_____ is a statement that returns a value to the statement called the function

return

You can create a scatter plot using the ___ method in Matplotlib.pyplot

scatter

When you have a long String of text, what method is used to break the string into individual words?

split

In JSON, the an array must be enclosed in ___

square brackets


Conjuntos de estudio relacionados

Astronomy - Unit 5: Inner and Outer Planets of Our Solar System

View Set

Small Parts Quiz 2: Thyroid and Other Neck Masses (pg. 41- 58)

View Set

Solving Quadratic Equations by Factoring / Assignment

View Set

Grade 7, module 10, week 33, Science Test

View Set

public speaking chapter 6 review

View Set

NURS 5220: Exam #1 Module 2: Ch 9, 10, 11, 12, 14, 15, 16

View Set