Chapter 2 - Variables and Expressions

Cards (32)

  • Variable - named item, such as x or num_people, that holds a value
  • assignment statement - assigns a variable with a value
  • Incrementing - increasing a variable's value
  • Identifier - aka name, is a sequence of letters, underscores, and digits, and must start with a letter or an underscore
  • object - represents a value and is automatically created by the interpreter when executing a line of code
  • garbage collection - deleting unused object
  • name binding - process of associating names with interpreter objects
  • value: "20", "abcdef", or "55"
  • type: a type of the object, such as int or str
  • identity: a unique identifier that describes the object
  • mutability: indicated whether the object's value is allowed to be changed (int and str are immutable)
  • floating-point number is a real number with decimal point
  • floating-point literal is written with the fraction part even if that fraction is 0, like 1.0, 0.0, or 99.0
  • compound operators - provide a shorthand way to update a variable, such as +=1, being shortened for age = age + 1
  • Overflow occurs when a value is too large to be stored in the memory allocated by the interpreter
  • expression - a combination of items, like variables, literals, operators, and parentheses, that evaluates to a value
  • literal - a specific value in code like 2
  • an operator is a symbol that performs a built-in calculation, which performs addition
  • module - a file containing Python code that can be used by other modules or scripts
  • a module is made available for use via the import statement
  • once a module is imported, any object defined in that module can be accessed using dot notation
  • Python comes with a standard math module to support such advanced math operations
  • A function is a list of statements that can be executed simply by referring to the function's name
  • the item passed to a function is argument
  • random module provides methods that return random values
  • seed - help generate a random number
  • Python uses Unicode to represent every possible character as a unique number, known as code point
  • a script is a file containing Python code that is passed as input to the interpreter
  • A module is a file containing Python code that is imported by a script, module, or interactive interpreter
  • A dot notation is used to reference an object in an imported module
  • An import is to execute the contents of a file containing Python code and make available the definitions from that file
  • __name__ is to determine if the file was executed as a script by the programmer or imported by another module