
Constants and variables questions and answers
Q1. What is meant by a ‘constant’?
A1. A constant is a data value which is fixed. It cannot change
Q2. Give some examples of constants.
A2. E.g. Pi = 3.14, MonthsInYear = 12, VAT = 17.5
Q3. Define ‘variable’.
A3. A variable is a name we give to a particular memory location that stores a piece of data.
Q4. What is an ‘identifier’?
A4. It is the name we give to a variable, for example. There might be lots of variables in a program so they all need to have their own name. You cannot, however used reserved words as identifiers.
Q5. What is meant by ‘declaring a variable’?
A5. This means creating the variable by giving it an identifier and a data type.
Q6. What is meant by ‘initialising a variable’?
A6. This means giving it a starting value.
Q7. Why do we use constants?
A7. Constants make programs easier to read. Also, if the value of the constant changes, you only need to change it once, where you declared the constant.
Q8. Why do we use meaningful names when we name a constant or variable?
A8. Meaningful names make programs much easier to read and understand both for yourself, for others and in the future.
Q9. How can you usually tell a constant from a variable in the Python programming language if convention has been followed?
A9. Python's convention is to put constants in capital letters.
Q10. What often happens in a programming language if you declare a variable to hold one data type but try to store a value of another data type in it?
A10. You usually (but not always) get an error. Sometimes, your programming language will let you do this.