CPSC Common Errors

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/6

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

7 Terms

1
New cards

SyntaxError

When the Python interpreter parses your code and finds incorrect code that does not conform to the syntax rules

  • Unclosed strings

  • Indentation issues

  • Misusing the assignment operator (=)

  • Misspelling Python keywords

  • Missing brackets, parentheses, or braces

2
New cards

IdentationError

When there's an indentation issue in your code. Common causes include mixing tabs with spaces, incorrect spacing, incorrectly nested blocks, or whitespace at the beginning of a statement or file.

3
New cards

NameError

If you attempt to use an identifier that hasn't been defined or might be out of scope. Other potential causes of a NameError include referencing a variable before its assignment or misspelling an identifier:

4
New cards

ValueError

You've entered invalid input to a function and it doesn't make sense to process it.

Function received an argument of the correct data type; however, the value itself is invalid. For example, the int() method accepts only integer string like "42", and passing something like "forty-two" will yield a ValueError:

5
New cards

TypeError

You've tried to perform an operation on two types and neither of the types understand what to do with the other.

You are performing an operation that is not supported or appropriate for the object data type. For example, trying to divide a string with an integer

Can also occur in situations like trying to loop over a non-iterable (such as a float or integer) or using incorrect argument types for built-in methods (like passing an integer to len(), which expects an iterable). Furthermore, calling a function with fewer arguments than required or comparing different data types can also lead to a TypeError

6
New cards

IndexError

When you attempt to access an index in a sequence, such as a list, tuple, or string, and it is outside the valid range. For instance, trying to access index 4 in a list with only three elements

7
New cards

AttributeError

You've tried to access an attribute of an object that doesn't exist.

When there's an attempt to access or utilize an attribute that an object or class doesn't possess. For instance,

-If we try to access the append() method on an integer value, we can get an AttributeError:

  • Output: As int object doesn't contain any append() method, it will give out AttributeError.