Data Types And Databases (Ch4) (M2) Flashcards
When programming, what should variables be given?
Variables should be given appropriate data types
What are the advantages of using the correct data types for variables?
Using the correct data types makes code more memory-efficient, robust and predictable.
What are the 5 main types of variable?
The five main types are:
Integer
Real (or Float)
Boolean
Character
String
What is a character?
A character is a single character, such as a letter, number or punctuation symbol
What is a string?
A string is a sequence of characters, including letters, numbers and punctuation
What is an integer?
An integer is a whole number
What is a real?
A real is a decimal number
What is a boolean?
A boolean is an answer that only has two possible values
What data type are telephone numbers stored as? Why?
Telephone numbers are always stored as a string, not an integer because they may include other symbols like “+” for example.
How much memory does an integer take up?
An integer takes up 2 bytes or 4 bytes
How much memory does a real take up?
A real takes up 4 bytes or 8 bytes
How much memory does a boolean take up?
A boolean takes up 1 bit, but 1 byte is usually used
How much memory does a character take up?
A character takes up 1 byte
How much memory does a string take up?
A string takes up 1 byte for every character in the string
What is casting?
Casting is converting a variable from one data type to another.
Give two examples of functions that let you manually convert between data types?
Languages have functions that let you manually convert between data types:
This can be done using:
int()
real() (or float())
bool()
str()
What does int(“1”) do?
Int(“1”) converts the string “1” to the integer 1
What does real(1) do?
Real(1) converts the integer 1 to the real number 1.0
What does bool(1) do?
Bool(1) converts the integer 1 to the boolean value True
What does str(True) do?
Str(True) converts the boolean value True to the string “True”
Give five examples of common arithmetic operators
+
Arithmetic operators:
*
/
MOD
DIV
What does modulus/MOD mean?
Modulus is how many whole numbers are left over after a division, e.g 5 MOD 26 = 1.
What does integers division/DIV do?
Integers Division/Quotient is how many times the number on the right fits into the number on the left. e.g 7 DIV 2 = 3, 2 goes into 7, 3 times.
However you only mention the remainder in Modulus.
What is exponentation?
Exponentiation is when one number multiplies by itself, the amount of times this is done, depends on the number.
What is 9 MOD 2
9 MOD 2 = 1
What is 12 DIV 8?
12 DIV 8 = 1
Give five examples of comparison operators
Comparison operators:
==
<> or !=
<
>
<=
>=
What is the assignment/comparison operator “=” used for?
The assignment/comparison operator “=” is used to assign values to constants or variables.
What do comparison operators do?
Comparison operators compare the expression on their left-hand side to the expression on their right-hand side and produce a Boolean value (either true or false).
Using WHILE, how can you create an infinite loop?
To create an infinite loop, use: WHILE True