Data Types Flashcards
What are data types
They are types of data that a variable can hold
What are the types of data types
Integer, Floating Point, String, Char, Boolean
Describe an Integer
- Holds whole numbers (positive, negative, zero).
- No decimals, used for counting and calculations.
- Signed (±) or unsigned (+ only).
Describe a floating point
- Stores decimal numbers.
- float (32-bit, less precise) vs. double (64-bit, more precise).
- Used in finance, science, and graphics.
Describe a string
- Holds text (letters, numbers, symbols, spaces).
- Enclosed in “ “ or ‘ ‘.
Describe a char
- Stores a single letter, digit, or symbol.
- Uses single quotes (‘A’).
Describe a Boolean
- Represents true or false.
- Used in conditions (if, while).
- In some languages, 1 = true, 0 = false.
What are variables and describe it a bit
- A variable is a named storage location in memory that holds a value, which can change during execution.
- It can store different data types (integers, floats, strings, etc.).
What is the difference between Dynamically and Statically Typed Languages
- Dynamically Typed (e.g., Python): Type is determined at runtime, allowing flexibility but potential type errors.
- Statically Typed (e.g., C#, Java): Type is set at compile-time, ensuring type safety but less flexibility.
What are constants
Constants are variables whose values cannot be changed when they’re assigned. They are used to represent values that should remain the same throughout the execution of a program, like mathematical constants (e.g., PI).
What is a scope
A scope defines where a variable or function is accessible within the code
What are the three types of scope?
Local, global and function scope
Describe a Local scope
Applies to variables inside a specific block (e.g., inside a function or loop).
Only accessible within that block.
Destroyed after the block finishes executing.
Describe a Global scope
Declared outside any function or block.
Accessible anywhere in the program after it’s declared.
Can be used or modified inside functions.
Describe a Function scope
Variables declared inside a function.
Only accessible within that function, similar to local scope.
Not available outside the function.
What are the three programming constructs
Sequence, Selection and Iteration
What is a sequence
It refers to the execution of instructions or statements one after the other, in the order they appear in the program. The statement is executed step by step without skipping any.
What is a selection
Selection allows the program to make decisions based on certain conditions. It uses if, elif and else to control the flow of execution depending if the conditions are true or false.
Explain the if, elif and else statements
The IF statement is the starting point of a conditional logic and only executes a piece of code if the conditions are true. if the condition is false it skips over that block of code. (Give an example)
The ELIF statement is used when you want to check multiple conditions in a sequence i.e if the previous ones were false
The ELSE statement follows the if and elif statement and provides an alternative block of code if the if statement is false. it is essentially a fall back option when the initial option isn’t met
What is Iterations
Iterations refers to repeating a set of instructions (loops) multiple times. It uses constructs like for and while loops. There are two types of loops which are pre conditional and post conditional loop.
What is pre conditional loop
The condition is checked before each iteration.
The loop may not run at all if the condition is false initially.
Examples: while, for.
What is post conditional loop
The condition is checked after each iteration.
The loop is guaranteed to run at least once, even if the condition is false initially.
Examples: do-while
What are functions
Functions are blocks of reusable codes designed to perform a specific task. They help organise codes and make them more efficient. They are two types which are: inbuilt functions and customer functions.
What are inbuilt functions
They are functions that are provided by the programming language itself. They are available to use without needing to define them. Examples are:
print(): Outputs text to the console.
len(): Returns the length of an object
type(): Returns the data type of an object.