Chapter 1: Programming Concepts Flashcards
Python-oriented
Identifier
A unique name for something (e.g. variable, constant, procedure, etc.) within the program
Variable
An identifier associated with a specific memory location, used to store data. Its value can change while a program runs
Constant
A named value within a program with a fixed value that does not change while the program runs
What are the benefits of declaring a constant? (2)
- When its value changes, only the declaration has to be changed
- It makes your code easier to read, debug and maintain
Variable names in Python can… (2)
- Be of any length
2. Use any upper- or lowercase letters, the underscore and the digits 0—9
Variable names in Python cannot… (2)
- Begin with a digit
2. Contain special characters (e.g. +, =), as they already have reserved uses
Why aren’t variable names beginning with underscores encouraged?
A considerable number of names beginning with underscores are already reserved for use by the system
How would you write “Pascal case” in Pascal case?
PascalCase
How would you write “camel case” in camel case?
camelCase
Data type
The type of data stored in a variable
What does the data type of a variable define? (3)
- The type of data stored in a variable
- How much memory is needed to store it
- The operations that can be performed on it
Integer
Data type for whole numbers
Real OR Float
Data type for fractional numbers
Character
Data type for a single character
String
Data type for text (over 1 character). Sometimes limited to a length of 255 characters
Boolean
A true or false value
How much memory is typically needed to store:
- An integer?
- A float?
- A single character?
- A boolean?
- 2 or 4 bytes
- 4 or 8 bytes
- 1 byte
- 1 byte, although 1 bit would suffice
Assignment
When a variable is given a value
Initialisation
Explicitly setting the starting values of variables
Algorithm
A series of instructions that solves a specific problem
What are the three main parts of program flow control?
- Sequence
- Selection
- Iteration
Sequence
Where instructions are executed one after another in series
Selection
Where the program executes certain instructions based on a condition
The two basic selection constructs are…
- If/else statements
- Case statements*
*Do not exist in Python