Chapter 1: Python Primer Flashcards
Python is an interpreted language, true or false?
true
interpreted language
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
machine code (x2)
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
high-level programming language (x3)
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)
examples of high-level programming languages (x10)
1) Python
2) PHP
3) Perl
4) Java
5) JavaScript
6) C#
7) C++
8) Ruby
9) Rust
10) GO
What does IDE stand for?
integrated development interface
IDE (integrated development environment)
a software application for building applications that combines developer tools into a single GUI (graphical user interface)
delimiter
a unique character or series of characters that indicates the beginning or end of a specific statement, string or function body set
examples of delimiters (x4)
1) Round brackets or parentheses: ( )
2) Curly brackets: { }
3) Double or single quotes for string literals: ‘ ‘ “ “
4) Escape sequence for comments: /*
Python is an object-oriented language, true or false?
true
object-oriented language
a language that uses classes and objects to create models
temperature = 98.6 is an example of an _____ statement
assignment
temperature = 98.6
in this example, temperature is an _____ (also known as name)
identifier
temperature = 98.6
in this example, 98.6 is an _____
object
temperature = 98.6
in this example, the identifier (also known as name) _____ references an instance of the _____ class having value _____
temperature
float
98.6
identifiers are case-sensitive in Python, true or false?
true
an identifier is implicitly associated with the _____ _____ of the object to which it refers
memory address
Python is a dynamically typed language, true or false?
true
dynamically typed language (x2)
any language that does not require declaring the data type of a variable
the variable type of checked during runtime
alias
a second identifier (also known as name) to an existing object
temperature = 98.6 original = temperature
in this example, original is an _____
alias
temperature = 98.6 original = temperature
in this example, identifiers temperature and original reference the same object 98.6, true or false?
true
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?
true
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?
true
both identifiers refer to the same object
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?
true
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?
- 6
103. 6
instantiation
creating a new instance of a class
the syntax for instantiating an object to invoke the _____ of a class
constructor
syntax of a constructor of a class
the class name followed by parentheses
constructor of a class (x3)
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
w = Widget()
in this example, the constructor does not require parameters, true or false?
true
w = Widget(a, b , c)
in this example, the constructor requires parameters, true or false?
true
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?
true
temperature = 98.6
in this example, the value _____ is a literal
98.6
literal
a value that is recognized as syntax for creating an object (also known as instance of a class)
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?
true
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?
sorted
data
Python’s classes may define one or more methods (also known as member functions), true or false?
true
Member functions (methods) are invoked on a specific object (also known as instance of a class) using _____ notation
dot
data.sort() is an example of a method invoked using _____ notation
dot
sorted(data) and data.sort() are the same, true or false?
true
in dot notation, the expression to the _____ of the dot identifies the object upon which the method is invoked
left
data.sort()
in this example, _____ is the identifier (also known as name)
data
in dot notation, the expression to the left of the dot can be an identifier (also known as name), true or false?
true
the dot operator can be used to invoke a method upon the immediate result of another operation, true or false?
true
response.lower().startswith(‘y’)
explain the order of what is evaluated in these method calls (x2)
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)
accessor methods (also known as get methods or getters)
methods that return information about an object’s state, but do not change its state
mutator methods (also known as update methods, set methods or setters)
methods that do change an object’s state
data.sort()
is this example an accessor method or a mutator method? why?
mutator method
the sort() methods changes the values of the identifier so they are sorted
immutable class
a class in which once an object of that class is instantiated (also known as created), its value cannot subsequently be changed
bool
mutable or immutable?
immutable
int
mutable or immutable?
immutable
float
mutable or immutable?
immutable
list
mutable or immutable?
mutable
tuple
mutable or immutable?
immutable
what is a list (array in other languages)?
a mutable sequence of objects
str (String in Swift)
mutable or immutable?
immutable
set
mutable or immutable?
mutable
what is a set?
mutable or immutable?
an mutable unordered set of distinct objects
what is a frozenset?
the immutable form of the set class
frozenset
mutable or immutable?
immutable
dict (also known as associative mapping or a dictionary)
mutable or immutable?
mutable
in Python, a Boolean value can be created from a nonboolean type using the syntax bool(foo) for value foo, true or false?
true
what is the syntax for creating a Boolean value from a nonboolean type?
bool(foo)
when a Boolean value is created from a nonboolean type, numbers will evaluate to _____ if zero and _____ if nonzero
false
true
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
false
true
a nonboolean value can be used as a condition in a control structure, true or false?
true
it is not mandatory to pass a value to bool(), true or false?
true
if a value is not passed to bool(), _____ is returned
false
control structure
a block of programming that analyzes variables and chooses directions in which to go based on given parameters or conditions
list (array in other languages), tuple, and str classes are _____ types in Python, a collection of values in which the order is significant
sequence
for sequence types in Python, the order of the collection of values is significant, true or false?
true
a list (array in other languages) instance stores a sequence of objects, true or false?
true
a list (array in other languages) is a _____ structure, as it stores a sequence of _____ to its elements
referential
reference
[‘red’, ‘green’, ‘blue’]
in this example, the list contains three _____ instances (also known as objects)
string
set
a collection of elements without duplicates and without an inherent order to those elements
a set is a collection of elements without _____ and an _____
duplicates
order
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
method
element
a set uses a hash table as its underlying data structure, true or false?
true
a set uses a _____ _____ as its underlying data structure
hash table
short-circuit
the compiler skips the execution or evaluation of a sub-expression in a logical expression (also known as a boolean expression)