communication Flashcards

1
Q

Rules for naming variables in Python?

A
  1. No spaces
  2. Cannot START with a number
  3. No special characters
  4. Cannot be named after a python function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The difference between compile-time vs. run-time errors?

A
  • Compile-time: the program won’t even run because it can’t understand the code you’ve written when your code does not comply with the python language (errors that correspond to the semantics or syntax) (ex. if something is misspelled, you forget to close the brackets, etc)
  • Run-time: error that we encounter during the code execution during runtime, code will still run and python understands it but what you’re telling it to do is wrong (ex. trying to divide something by 0)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Review the difference between accessor and mutator functions?

A
  • Accessor methods are used to obtain data in a class object. You name accessor methods starting with the word “get”. All accessor methods must include a return statement that returns the value that the method is intended to return.
    (ex: def getNumber(self):
    return self.__number)
  • Mutator methods are used to change data in a class object. Mutator methods’ names begin with the word set.
    (ex: def setNumber(self, num):
    self.__number = num)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Review how to create constructors and functions in a class?

A
  • Constructors are special methods used for initializing objects in a class.
    • We define a class.
    • The __init__ method is the constructor. It takes the special parameter self (which refers to the instance being created) and other parameters
    • Inside the constructor, we initialize the attributes of the class using the passed parameters.
    • When an instance (my_instance) of the class is created, the __init__ method is automatically called, and the attributes are initialized based on the provided values.
    • We can then access the attributes of the instance using dot notation (my_instance.attribute1, my_instance.attribute2).
  • Functions in a class are methods that perform operations on the class’s attributes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly