top of page

Different errors in different programming languages part 1: python

  • Jan 23, 2023
  • 1 min read

Python errors can be confusing and I want to help you understand them so I am writing this blog post for just that.


Syntax errors:

  • Also called parsing errors

  • happen when code is parsed/processed to assess for syntax correctness

  • you will get this error message for a basic syntax mistake.

correct syntax:

# this will print hello world and there is no error

x = 0

if x == 0:

print("Hello World")

else:

print("x does not equal 0 so this won\'t print")


incorrect syntax:

this is supposed to print hello world but it gives us a syntax error

x = 0

if x == 0:

print("Hello World")

else:

print("This should give us an error")


For the second example: the problem is:

  • There is no hashtag for the comments

  • there is no indentation

here is another example of a syntax error:

# This is supposed to print "This is true", but it gives us a syntax error

if True != False

print("This is true")

else:

print("This is false"


the issues are:

  • There is a missing colon

  • there is a missing parenthesis

And there are exceptions

exceptions:

  • Errors detected during code execution

There are different exception types in python.

Common built-in Python exceptions include:

  • ZeroDivisionError

  • TypeError

  • IndexError

  • NameError

type error:

>>> a = 5 + '4'


index error:

>>> c = [1, 2, 3, 4]

>>> print(c[20])


NameError:

>>> a = b + 15


Zero Division error:

>>> d = 1/0



Comments


Programming blog

©2023 by Programming blog. Proudly created with Wix.com

bottom of page