Chapter 1: Python Primer Flashcards

1
Q

Python is an interpreted language, true or false?

A

true

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

interpreted language

A

a high-level language run by an interpreter, a program that directly executes instructions written in the programming or scripting language without first compiling it into machine code

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

machine code (x2)

A

1) any low-level programming language, which consists of machine language instructions that are used to control a computer’s CPU (central processing unit)
2) a numerical language designed to run as fast as possible

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

high-level programming language (x3)

A

1) any programming language with strong abstraction from the computer
2) closer to human languages (easier to read) and further from machine languages
3) focuses more on logic than underlying hardware components (eg. memory management)

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

examples of high-level programming languages (x10)

A

1) Python
2) PHP
3) Perl
4) Java
5) JavaScript
6) C#
7) C++
8) Ruby
9) Rust
10) GO

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

What does IDE stand for?

A

integrated development interface

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

IDE (integrated development environment)

A

a software application for building applications that combines developer tools into a single GUI (graphical user interface)

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

delimiter

A

a unique character or series of characters that indicates the beginning or end of a specific statement, string or function body set

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

examples of delimiters (x4)

A

1) Round brackets or parentheses: ( )
2) Curly brackets: { }
3) Double or single quotes for string literals: ‘ ‘ “ “
4) Escape sequence for comments: /*

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

Python is an object-oriented language, true or false?

A

true

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

object-oriented language

A

a language that uses classes and objects to create models

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

temperature = 98.6 is an example of an _____ statement

A

assignment

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

temperature = 98.6

in this example, temperature is an _____ (also known as name)

A

identifier

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

temperature = 98.6

in this example, 98.6 is an _____

A

object

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

temperature = 98.6

in this example, the identifier (also known as name) _____ references an instance of the _____ class having value _____

A

temperature
float
98.6

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

identifiers are case-sensitive in Python, true or false?

A

true

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

an identifier is implicitly associated with the _____ _____ of the object to which it refers

A

memory address

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

Python is a dynamically typed language, true or false?

A

true

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

dynamically typed language (x2)

A

any language that does not require declaring the data type of a variable

the variable type of checked during runtime

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

alias

A

a second identifier (also known as name) to an existing object

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

in this example, original is an _____

A

alias

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

in this example, identifiers temperature and original reference the same object 98.6, true or false?

A

true

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

in this example, either identifier temperature or original can be used to access the 98.6 object, true or false?

A

true

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

if an object supports behaviors that affect its state, changes through an alias will be apparent when using the other identifier, true or false?

why is this so?

A

true

both identifiers refer to the same object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
temperature = 98.6
original = temperature
temperature = temperature + 50

the temperature identifier has been assigned to a new value, while original continues to refer to the previously existing value, true or false?

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
temperature = 98.6
original = temperature
temperature = temperature + 50

what is the value of the floating-point object original references?

what is the value of the floating-point object temperature references in the last line?

A
  1. 6

103. 6

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

instantiation

A

creating a new instance of a class

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

the syntax for instantiating an object to invoke the _____ of a class

A

constructor

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

syntax of a constructor of a class

A

the class name followed by parentheses

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

constructor of a class (x3)

A

a special member function of a class that is executed when a new object of that class is created (also known as instantiated)

it has the same name as the class

it does not have any return type, not even void

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

w = Widget()

in this example, the constructor does not require parameters, true or false?

A

true

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

w = Widget(a, b , c)

in this example, the constructor requires parameters, true or false?

A

true

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

Many of Python’s built-in classes support a literal form for designating new instances of a class (also known as objects), true or false?

A

true

34
Q

temperature = 98.6

in this example, the value _____ is a literal

A

98.6

35
Q

literal

A

a value that is recognized as syntax for creating an object (also known as instance of a class)

36
Q

A way to indirectly create an instance of a class (also known as an object) is to call a function that creates and returns such an instance, true or false?

A

true

37
Q

Python supports traditional functions that are invoked with syntax such as sorted(data)

in this example, what is the function name?

what is the argument sent to the function?

A

sorted

data

38
Q

Python’s classes may define one or more methods (also known as member functions), true or false?

A

true

39
Q

Member functions (methods) are invoked on a specific object (also known as instance of a class) using _____ notation

A

dot

40
Q

data.sort() is an example of a method invoked using _____ notation

A

dot

41
Q

sorted(data) and data.sort() are the same, true or false?

A

true

42
Q

in dot notation, the expression to the _____ of the dot identifies the object upon which the method is invoked

A

left

43
Q

data.sort()

in this example, _____ is the identifier (also known as name)

A

data

44
Q

in dot notation, the expression to the left of the dot can be an identifier (also known as name), true or false?

A

true

45
Q

the dot operator can be used to invoke a method upon the immediate result of another operation, true or false?

A

true

46
Q

response.lower().startswith(‘y’)

explain the order of what is evaluated in these method calls (x2)

A

1) response.lower() is evaluated, which returns a new string instance (also known as object)
2) startswith(‘y’) is called on the new string instance (also known as object)

47
Q

accessor methods (also known as get methods or getters)

A

methods that return information about an object’s state, but do not change its state

48
Q

mutator methods (also known as update methods, set methods or setters)

A

methods that do change an object’s state

49
Q

data.sort()

is this example an accessor method or a mutator method? why?

A

mutator method

the sort() methods changes the values of the identifier so they are sorted

50
Q

immutable class

A

a class in which once an object of that class is instantiated (also known as created), its value cannot subsequently be changed

51
Q

bool

mutable or immutable?

A

immutable

52
Q

int

mutable or immutable?

A

immutable

53
Q

float

mutable or immutable?

A

immutable

54
Q

list

mutable or immutable?

A

mutable

55
Q

tuple

mutable or immutable?

A

immutable

56
Q

what is a list (array in other languages)?

A

a mutable sequence of objects

57
Q

str (String in Swift)

mutable or immutable?

A

immutable

58
Q

set

mutable or immutable?

A

mutable

59
Q

what is a set?

mutable or immutable?

A

an mutable unordered set of distinct objects

60
Q

what is a frozenset?

A

the immutable form of the set class

61
Q

frozenset

mutable or immutable?

A

immutable

62
Q

dict (also known as associative mapping or a dictionary)

mutable or immutable?

A

mutable

63
Q

in Python, a Boolean value can be created from a nonboolean type using the syntax bool(foo) for value foo, true or false?

A

true

64
Q

what is the syntax for creating a Boolean value from a nonboolean type?

A

bool(foo)

65
Q

when a Boolean value is created from a nonboolean type, numbers will evaluate to _____ if zero and _____ if nonzero

A

false

true

66
Q

when a Boolean value is created from a nonboolean type, sequences and other container types like strings and lists evaluate to _____ if empty and _____ if nonempty

A

false

true

67
Q

a nonboolean value can be used as a condition in a control structure, true or false?

A

true

68
Q

it is not mandatory to pass a value to bool(), true or false?

A

true

69
Q

if a value is not passed to bool(), _____ is returned

A

false

70
Q

control structure

A

a block of programming that analyzes variables and chooses directions in which to go based on given parameters or conditions

71
Q

list (array in other languages), tuple, and str classes are _____ types in Python, a collection of values in which the order is significant

A

sequence

72
Q

for sequence types in Python, the order of the collection of values is significant, true or false?

A

true

73
Q

a list (array in other languages) instance stores a sequence of objects, true or false?

A

true

74
Q

a list (array in other languages) is a _____ structure, as it stores a sequence of _____ to its elements

A

referential

reference

75
Q

[‘red’, ‘green’, ‘blue’]

in this example, the list contains three _____ instances (also known as objects)

A

string

76
Q

set

A

a collection of elements without duplicates and without an inherent order to those elements

77
Q

a set is a collection of elements without _____ and an _____

A

duplicates

order

78
Q

an advantage of a set over a list (array in other languages) is that it has an optimized _____ for checking whether a specific _____ element is contained in the set

A

method

element

79
Q

a set uses a hash table as its underlying data structure, true or false?

A

true

80
Q

a set uses a _____ _____ as its underlying data structure

A

hash table

81
Q

short-circuit

A

the compiler skips the execution or evaluation of a sub-expression in a logical expression (also known as a boolean expression)