ANI

7 Python Errors actually have features

Photo by writer | Ideogram

Python has become a major tool for many database data to deceive data and electronic purposes because how it is easy to use. The language language is basically the gold level in the data community.

Once you are familiar with Python, you often meet bad knowledge whenever you produce incorrect syntax or violates Python's laws. It is included in the Python philosophy of Pythosophy to emphasize that errors need clearly displayed, following the goal that It is easy to ask forgiveness than permission (EAFP), which allows you to make code first before you know if there is a mistake.

Some Python errors are not bugs but features that help users improve their Python skills. Understanding these errors is important if we wish to use them as a guide for our work with purpose. For learning purposes, this article will examine seven different mistakes of various python.

Let's get into it.

1. Syntax Error

Syntax error is recommended when the Python Passer meets the wrong code Syntax not following PYTHON LOGIC. Any negative code will be displayed as an error, which becomes basic in Python's Design. Let's look at the mistake in the Python code.

The above code will suggest a syntax error below.

 Cell In[6], line 1
    if True print("hello")
            ^
SyntaxError: invalid syntax

The error shows that we do not attach to the Python Synstax. The Synstax error design is the purpose of the purpose of Pynthon which indicates basically that any deviation from the required level requires repair. It will not work any code that does not follow the grammar and are trying to guess what we want to do.

The syntax error confirms that it is always a clear and undeniable code. It also helps to work together, as the quality remains consistent regardless of any Python language.

2. Reference Error

Anyone who is using Python, there are many times when we use alignment such as lists or tuples for our work. To access data within these sequences will require us to use display methods.

Well, what happens when we reach an indicator outside its borders? Python will throw an error message. Let's see what happens we use real code.

lst = [1, 2, 3]
print(lst[5])

The above code will throw the following error:

IndexError                                Traceback (most recent call last)
Cell In[2], line 2
      1 lst = [1, 2, 3]
----> 2 print(lst[5])

IndexError: list index out of range

The error is displayed as an indicator error, which is informed that the indicator is outside the range. The error is intended, as it shows that the Python does not allow the quiet wrap (case where accessing data without automatic ties increases the structure of the building at prices.

If it were possible, behavior will introduce hidden bugs that cause many problems in a very complex pipe. For example, relief from the Python's network will break the loop where the indicator is outside the boundaries, which will not happen if no indicator errors exist.

3. Important Error

As we know, the keys of the Object ornency Maps with pricing stored in. The EXEX Error EXIRE occurs an important error of the dictionary when the appearance fails because the key is not in the dictionary item. Let's see how it works in the Python code.

d = {'a': 1}
print(d['b'])

The above code will suggest the following error:

KeyError                                  Traceback (most recent call last)
Cell In[3], line 2
      1 d = {'a': 1}
----> 2 print(d['b'])

KeyError: 'b'

The key error is suggested because no 'B' key in the dictionary. It is design that Python is clearly lifting this mistake, because we do not want the unintentional behavior to use placelder prices for a silent key.

Using this key error, we can find any syntax errors or perceptive errors during the dictionary instead of guessing if the key is available or not. Error is also helpful when combined with TRY / without syntax to create a new key in the dictionary if not.

4. Name Error

The word error is a mistake that happens when we call undescribed flexibility. There is a similar charge called an unprotected area, a subclass error of the name, where we have the Python job trying to access the change of place before it is described. Let's look at the error in the code below.

Error is displayed at the bottom.

NameError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 print(x)

NameError: name 'x' is not defined

The code suggests an error because we have never described the 'X' variables. Let's look at the Python code for an insecure environment.

def foo():
    x = x + 1  

foo()

Error is displayed at the bottom.

Cell In[4], line 2, in foo()
      1 def foo():
----> 2     x = x + 1

UnboundLocalError: cannot access local variable 'x' where it is not associated with a value

Both errors are suggested because we need to follow the Python error law allows users to hold typos or bugs quietly, rather than silent Python will interrupt our Python work.

5. Type the error

The kind error is an error raised when doing some work at something but in the form of the wrong thing. Let us show the error of the Python code below.

The error is suggested as shown at the bottom.

TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 next([1, 2, 3])

TypeError: 'list' object is not an iterator

The type error occurs because we cannot pass the next item in the next work.

Python is designed to use items only in their intended ways. That is why, this error helps users protect hidden bugs and ensure that the work is active as targeted.

6. Error of the value

Unlike the kind of error, the price error is suggested when the work gets the correct debate but the incorrect amount. Let's display the Python code.

The error is displayed in this result below.

ValueError                                Traceback (most recent call last)
Cell In[8], line 1
----> 1 int("abc")

ValueError: invalid literal for int() with base 10: 'abc'

You can see that the price error occurs because we pass the unique number of rope. The worker gets the right kind but not the right amount, so the signon signs is wrong. It is the Python design that shows that the error occurs instead of apathy or putting the value of place in the area, as that may interfere with our work.

7. Syncment error

A consent error occurs when a guits statement is used and the situation is not achieved or false. It is a useful feature of confusing and enforcing any consideration of your Python work. Let's look at the mistake code below.

assert 2 + 2 == 5, "It's not right"

You will find the next error.

AssertionError                            Traceback (most recent call last)
Cell In[13], line 1
----> 1 assert 2 + 2 == 5, "It's not right"

AssertionError: It's not right

Code 2 + 2 == 5 Produce the amount of lies, which leads to the permission error when using a guefs statement. We can regularly apply information when using power, similar to what you see above.

The consent error helps users to provide development for development, as we can set a failure program that allows for simple repairs. By choosing the conditions where the permission of the approval is raised, we also receive more control of how the mistake should behave.

Store

Many data experts use Python. The tongue of the programs sometimes suggests the errors in reality, and therefore we should keep our eyes open and check our tracebam.

I hope this has helped!

Cornellius Yudha Wijaya It is a scientific science manager and the database author. While working full-time in Allianz Indonesia, she likes to share the python and data advice with social media and media writing. Cornellius writes to a variety of AI and a study machine.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button