VARIABLES, DATA TYPES and CONSTANTS Flashcards
What does Variable do?
They hold values
Int -
Whole number such as 156, 0, -54
Float/Real
Float
Number with a fractional part such as 1.5276, -68.4, 20.0
Char or Character
A single ASCII character
str
String
str
zero or more characters
Boolean
bool
Can only take the values true or false
Why declare a constant
Prevents the code accidently being changed by a part of code
It shows a programmer that the value that the value should stay the same throughout the program.
Constants are typically shown in uppercase
Words are separated with an underscore, e.g. MIN_AGE
This is known as snake case
A CONSTANT CAN NEVER CHANGE ITS VALUE
A CONSTANT CAN BE CHANGED BY A PROGRAMMER BEFORE THE PROGRAM IS COMPILED OR TRANSLATED.
A CONSTANT CAN NEVER CHANGE ITS VALUE
A CONSTANT CAN BE CHANGED BY A PROGRAMMER BEFORE THE PROGRAM IS COMPILED OR TRANSLATED.
31 // 7
how many times it goes in
31 % 7
the remainder