python theory Flashcards

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

A

List

25
Q

______ is a series of pairs of things generally the key and a value

A

Dictionary

26
Q

The data type { } bracket is used with

A

dictionaries

27
Q

do keys in dictionaries have to be string

A

false, no they can also be number

28
Q

customer_29876[“city”] = “Toronto” what is happening here

A

for a dictionary a new pair with a key of city and value of Toronto is being added

29
Q

can you define a dictionary with no key value pairs and if so what is it called

A

yes, its the empty dictionary

30
Q

the index (in the list) or the key (in the dictionary) can be used to change the value of an element (True or False)

A

True

31
Q

.values (): is used for and need in

A

looping dictionary values

32
Q

within loops don’t forget to break it or else it will create

A

errors or stop functioning

33
Q

can you loop through the keys of the dictionary (true or false)

A

true, use .keys() to do that

34
Q

what keyword do you use to list all the elements in the dictionary and what must you make sure

A

the keyword is .items and you use make sure to use 2 variables to check in the for line

35
Q

A _____ is a block of Python code that robotically does the same thing again
and again, whenever you invoke its name

A

function

36
Q

what keyword is used to start a function

A

def

37
Q

a function doesn’t do anything until it’s ____

A

called

38
Q

numbers inside the parentheses of a function is known as an

A

argument add_numbers(53, 109)

39
Q

A variable inside the parentheses in a function definition is known as a

A

parameter – def add_numbers(first_number, second_number):

40
Q

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

A

positional

41
Q

for a dictionary what does this command do find_something(customers, 2, “last name”)

A

finds the last name of customer 2 in a dictionary named customers

42
Q

def find_something(dict, inner_dict, target): 2 print(dict[inner_dict][target])

A

printing a specific part of the dictionaries within one

43
Q

_________ arguments are arguments that need to be included in the proper position or order.

A

positional

44
Q

in the following code, the first argument is a _____________ argument.
give_greeting(“Hello there”, first_name=”Al”)

A

positional

45
Q

In the following code, the second argument is a _____________ argument.
give_greeting(“Hello there”, first_name=”Al”)

A

keyword

46
Q

_____ arguments (or named arguments) are values that, when passed into a function, are identifiable by specific parameter names

A

keyword

47
Q

______ arguments enable you to omit arguments for some parameters

A

Optional

48
Q

How does the function handle the optional arguments? It puts them in a _______

A

dictionary

49
Q

to have a function that displays additional information (optional arguments) you must use

A

** two asterisks

50
Q

how do you assign a default parameter in the function

A

def analyze(qty = 0):

51
Q

a function is a variable (True or False)

A

True

52
Q

A ______ variable is one you define in the main body of your code—that is,
not in a function

A

global

53
Q

A ______ variable is one that you define in a function.

A

local

54
Q

def call_another_function() what is happening here

A

a function is defined by calling another function

55
Q

how do you define a class

A

class name:

56
Q

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

A

pass

57
Q

what is a part of blueprint (class) that allows us to specify what should happen when the object is constructed

A

a constructor (aka. initializing an object)

58
Q
A