<jupyter_start><jupyter_text>Type of error in python, how to handle them<jupyter_code>def x(string):
    string == string[::-1]

print(x(1))<jupyter_output><empty_output><jupyter_text>The error above happens because the program is expecting a string  The function we can apply is **try**  The try and except block in Python is used to catch and handle exceptions. Python executes code following the try statement as a “normal” part of the program. The code that follows the except statement **is the program’s response** to any exceptions in the preceding try clause.  reference: https://realpython.com/python-exceptions/:~:text=except%20is%20used%20to%20catch,encountered%20in%20the%20try%20clause.<jupyter_code>def x(string):
    string == string[::-1]

# The try part is the code where you expect everything noraml and/or correct
try:
    print(x(1))
# The except part is the code where you excepct something wrong
except TypeError:
    print("You have to enter words, not numbers, try again")<jupyter_output><empty_output><jupyter_text>The next function is called **raise**  We can use raise to throw an exception **if a certain condition occurs.**  reference: https://realpython.com/python-exceptions/:~:text=except%20is%20used%20to%20catch,encountered%20in%20the%20try%20clause.Example 1<jupyter_code>a = 5

if a % 2 != 0:
    raise Exception("The number should´t be an odd integer")<jupyter_output><empty_output><jupyter_text>Example 2<jupyter_code>def x(string):
    try:
        if len(string) == 0:
            # Throws an exception when a condition (string == 0) is met
            raise ValueError("You should´t leave without input")
        return string == string [::-1]
    except ValueError as ve:
        print(ve)
        return False
try:
    # Code if everything goes normal
    print(x(""))
# Code if something goes wrong (specifically if a TypeError)
except TypeError:
    print("You have to enter words")<jupyter_output><empty_output><jupyter_text>The next function is **assert**This function works similar to raise, raises an exception when meeting a certaing condition, the difference is that this function work with booleans (True, False)<jupyter_code>x = 10
assert(x < 10), "This number isn´t supposed to be greater than 10"

# if assert == True, x stored, if assert == False, raises an exception<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09732256693582661, 'fraction_numerical': 0.021249468763280918, 'mean_word_length': 4.812345679012346, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '343126', 'license': 'Apache-2.0', 'n_tokens_mistral': 729, 'n_tokens_neox': 697, 'n_words': 260, 'path': 'python_projects/intermidiate_python/type_errors.ipynb', 'repo_name': 'DavGarza/Learning-data-science', 'size': '2353'}