• 04 April

    SyntaxError: ‘Return’ Outside Function

    In this post, we will see about SyntaxError: 'Return' Outside Function in Python. This error will generally occur when you do not put the return statement indentation properly with function definition. 💡 Did you know? Unlike C,C++ or java, Python uses whitespace for indentation. All statements which are at same distance on right belong to […]

  • 01 April

    SyntaxError: eol while scanning string literal

    In this post, we will see about SyntaxError eol while scanning string literal. SyntaxError are raised when python interpreter is translating source code in bytes and it generally means there is something wrong with the syntax. These errors are also easy to figure out and fix as well. You will get SyntaxError eol while scanning […]

  • 26 March

    Find average of list in Python

    There are multiple ways to find the average of the list in Python. Using sum() and len() We can use sum() to find sum of list and then divide it with len() to find average of list in Python. Here is the quick example of the same. [crayon-66377d0f66934418791455/] Output: Average of listOfIntegers: 3.0 Using reduce(), […]

  • 26 March

    Python list files in directory

    In this post, we will see how to list all files in a directory in Python. There are multiple ways to list all files in a directory in Python. Using os.walk Python os module provides multiple function to get list of files. List all files in directory and its subdirectories using os.walk(path). It iterates directory […]

  • 23 March

    Python String to bytes

    In this post, we will see how to convert String to bytes in Python. There are two ways to convert String to bytes in Python. Using bytes() constructor You can use bytes() constructor to convert String to bytes in Python. You need to pass string and encoding as argument. Here is an example: [crayon-66377d0f6774f379260041/] Output: […]

  • 23 March

    Python write to text file

    In this post, we will see how to write to a text file. There are multiple modes in which you can write to text file. Create txt file(‘x’) It will open the file in 'X' mode which will create new file and return error in case file already exists. [crayon-66377d0f678ff260158566/] Here is content of fruits.txt. […]

  • 23 March

    Read File Into String in Python

    1. Introduction to the Problem Statement When working with file operations in Python, a common requirement is to read the contents of a file into a string. This can be essential for various applications, such as data processing, text analysis, or just simple file manipulation. For instance, if we have a file named example.txt with […]

  • 24 December

    TypeError: ‘list’ object is not callable

    In this post, we will see how to resolve TypeError: ‘list’ object is not callable in python. Let’s first understand why we get this error. In python, a built-in name is a name in which the python interpreter assigns predefined value. The value can be objects, functions or classes. All these built-in names will be […]

  • 22 December

    Python list of lists

    In this post, we will see how to create a list of lists in python. It is quite easy to create list of lists in Python. You just need to use list’s append method to create list of lists. Here is simple example to create list of lists in Python. [crayon-66377d0f69284191951678/] Output: List of Lists: […]