python theory Flashcards

(58 cards)

1
Q

Python’s governing body recommends breaking up multi-word
variables with

A

underscore (__)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

another way to write age = age + 1 is

A

age += 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In a list, these
values are known as

A

elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

enclosed in square brackets is what kind of data type

A

lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Return keyword is used to show the results in or within using

A

functions, methods, lambdas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A list can contain various data types (True or False)

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

.append keyword for the list does what

A

add element to the end of the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

todays_tasks = todays_tasks + [“Washing the car”, “Cleaning the car”]
what is happening in the code

A

a way to add elements to the list using a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

if you want to add something new in the middle of the list what keyword would you use

A

insert

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

cities.insert(0, “New York”) what is happening here

A

using insert the work new york is places first in the list of cities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

in slicing the number following the colon is the index number of the element that
comes _____(when) the last element in the slice:

A

after

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

keywords used to remove items in a list

A

del and .remove

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

the .remove need what

A

the string value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

to strike off an element of a list the keyword used is

A

.pop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is similar to a list but elements are fixed unless the entire thing is redefined

A

tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

We’re looping through the list y and assigning each element to the variable x. Code the first line.

A

for x in y:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

what statement is used to stop the loop

A

break

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

contains an element less than 1, meaning

A

c < 1:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

that you ____ provide a variable to hold the user’s input. If you omit
it python breaks

A

must

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

the default data type of a input by a user is

A

string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what does .lower() do

A

for a list, variable or anything it changes all to lower case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

what does .title() do

A

The first letter of the word is capitalized like “Cheyenne” to “Cheyenne”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

the data type that has ( ) brackets

A

tuples

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

the data type that has [ ] brackets

25
______ is a series of pairs of things generally the key and a value
Dictionary
26
The data type { } bracket is used with
dictionaries
27
do keys in dictionaries have to be string
false, no they can also be number
28
customer_29876["city"] = "Toronto" what is happening here
for a dictionary a new pair with a key of city and value of Toronto is being added
29
can you define a dictionary with no key value pairs and if so what is it called
yes, its the empty dictionary
30
the index (in the list) or the key (in the dictionary) can be used to change the value of an element (True or False)
True
31
.values (): is used for and need in
looping dictionary values
32
within loops don't forget to break it or else it will create
errors or stop functioning
33
can you loop through the keys of the dictionary (true or false)
true, use .keys() to do that
34
what keyword do you use to list all the elements in the dictionary and what must you make sure
the keyword is .items and you use make sure to use 2 variables to check in the for line
35
A _____ is a block of Python code that robotically does the same thing again and again, whenever you invoke its name
function
36
what keyword is used to start a function
def
37
a function doesn't do anything until it's ____
called
38
numbers inside the parentheses of a function is known as an
argument add_numbers(53, 109)
39
A variable inside the parentheses in a function definition is known as a
parameter -- def add_numbers(first_number, second_number):
40
Arguments like this are ______ arguments—arguments that are loaded into function parameters in order, like a line of customers loaded into the cars of a theme park ride
positional
41
for a dictionary what does this command do find_something(customers, 2, "last name")
finds the last name of customer 2 in a dictionary named customers
42
def find_something(dict, inner_dict, target): 2 print(dict[inner_dict][target])
printing a specific part of the dictionaries within one
43
_________ arguments are arguments that need to be included in the proper position or order.
positional
44
in the following code, the first argument is a _____________ argument. give_greeting("Hello there", first_name="Al")
positional
45
In the following code, the second argument is a _____________ argument. give_greeting("Hello there", first_name="Al")
keyword
46
_____ arguments (or named arguments) are values that, when passed into a function, are identifiable by specific parameter names
keyword
47
______ arguments enable you to omit arguments for some parameters
Optional
48
How does the function handle the optional arguments? It puts them in a _______
dictionary
49
to have a function that displays additional information (optional arguments) you must use
** two asterisks
50
how do you assign a default parameter in the function
def analyze(qty = 0):
51
a function is a variable (True or False)
True
52
A ______ variable is one you define in the main body of your code—that is, not in a function
global
53
A ______ variable is one that you define in a function.
local
54
def call_another_function() what is happening here
a function is defined by calling another function
55
how do you define a class
class name:
56
what keyword can be used when you do not have any code in the class or a function but want to write more code outside it
pass
57
what is a part of blueprint (class) that allows us to specify what should happen when the object is constructed
a constructor (aka. initializing an object)
58