Data Types, Errors Flashcards

1
Q

Integer Data Type

A
  • Referred to as ‘int’, holds integer values.
  • Integers are numbers without a fractional or decimal part.
  • ex.) age = 25
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Float Data Type

A
  • ‘float’
  • Real numbers with decimal point.
  • ex.) PI = 3.14159
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

String Data Type

A
  • ‘str’
  • Enclosed in either (‘ ‘) or (“ “) quotation marks.
  • ex.) name = ‘Alice’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to check the type of variable

A

type(variable_name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the types of errors?

A

Syntax, runtime, logic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax Errors

A
  • Syntax refers to the structure of a program and the rules about that structure.
  • Definition: Syntax errors are errors in your code that the computer can’t interpret In python these errors include:
  • Spelling errors
  • The omission of important characters (eg. missing colon, bracket, mismatched quotes)
  • Wrong indentation
  • When does a syntax error occur?:
    Occurs during the compilation or interpretation phase of the program, which analyzes the structure of the code.
  • Effect:
    Program cannot be executed until the syntax error is fixed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Runtime Errors

A
  • Definition: Errors that are not detected until run time. Occur when a statement is executed, and something unexpected or invalid happens during runtime.

Often caused by:
- Invalid inputs
- Division by zero
- Can’t find some data because it doesn’t exist. eg.) IndexError: out of range index.
- Mismatched data types: performing operations between incompatible data types can result in a ‘TypeError’. ex.) result = “5” + 2 # TypeError: can only concatenate str (not “int”) to str

Effect:
- Program may terminate
- May produce unexpected or undesirable behavior.
- Program may crash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Logic Errors

A
  • Definition: Do not produce error messages, instead they do not do what you intended the code to do.
  • Produces incorrect results, like miscalculations, wrong decisions, unpredictable behavior.

Causes:
- Incorrect conditional statements, etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Type Conversion (Casting)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly