Posts

Showing posts from January, 2024

Debugging with Python - Part 1

Debugging with Python Part 1 Errors Debugging is the process of identifying and fixing bugs (i.e. errors in the code which lead to incorrect software functionality). So, before we discuss “ fixing bugs ”, let’s explore the types of errors we might make in our programs. We will be looking at the three basic types of errors; namely compilation errors, runtime errors and logical errors. 1. Compilation Errors Compilation errors occur during the compilation phase and prevent the program from running. These are generally syntax errors (i.e. violations of the syntactic rules of the programming language). However, Python is an interpreted language, and the Python interpreter checks for syntax errors as it reads and parses the script. It won’t run the script and will output an error message indicating the type of compilation error and the line of code so that we can easily rectify our mistake. Let’s look at two of the most familiar compilation errors we might encount...

Strings and RegEx with Python

Strings and RegEx with Python Strings & RegEx with Python Strings A String or a str object in Python, is a sequence of Unicode characters. In python, strings are written within either single or double quotes. We may also use triple quotes ( ''' ) or ( """ ) for multiline strings. Strings may include letters, numbers, symbols, and even spaces. Since, Python does not have a character data type, a single character is defined as a single length String. Strings are immutable, hence once created, their values cannot be modified. Strings are considered as arrays of characters. Hence, they possess properties similar to arrays. Strings support common sequence operations such as concatenation ( + ), repetition ( * ), slicing, indexing etc. Let’s write a simple code snippet to extract words from a sentence using indexing and slicing. The variable word1 is assigned a substring ( sentence[6:11] ) sliced from the variable sentence . It inclu...