• 26 April

    Python pretty print json

    In this post, we will see how to pretty print JSON in Python. We can use the Python JSON module to pretty-print JSON data. We can use json’s dumps() method with indent parameter to pretty print json data. Python pretty print json string Let’s understand this with the help of example. [crayon-66376c8d83e9c076938791/] Output: [ { […]

  • 21 April

    Python Print without Newline

    In this post, we will see how to print without Newline in Python. In python, when you use two print statements consecutively, it will print in different line. [crayon-66376c8d8549d366500376/] Output: Hello world from Java2blog As expected, we got Hello world and from Java2blog If you want to print these two print statements in the same […]

  • 21 April

    Remove first element from list in Python

    In this post, we will see how to remove the first element from a list in python. Using list.pop() We can use list.pop() method to remove the first element from the list. [crayon-66376c8d8588d680201796/] Output: List Of Fruits are: [‘Orange’, ‘Apple’, ‘Grapes’, ‘Mango’] List Of Fruits after removing first element: [‘Apple’, ‘Grapes’, ‘Mango’] Removed Fruit: Orange […]

  • 07 April

    TypeError: ‘NoneType’ object is not iterable

    In this post, we will see about TypeError: NoneType object is not iterable. You will get this error if you are iterating over object of type None in for or while loop. Let’s understand with help of example. [crayon-66376c8d85ff3042932891/] If countryList is of type None, then you can get this error. Let’s see a scenario […]

  • 07 April

    TypeError: unhashable type: ‘list’

    In this post, we will see about TypeError: unhashable type: 'list'. You will get this error when you are trying to put list as key in dictionary or set because list is unhashable object.TypeError: unhashable type is generally raised when you try to hash object which is unhashable. Let’s see this with help of example: […]

  • 07 April

    Indexerror: list Index Out of Range

    In this post, we will see about Indexerror: list Index Out of Range in Python. While working with list, you can access its elements by its index. You will get this error when you are trying to access an index that does not exist. Let’s see with the help of example. [crayon-66376c8d87efd428080206/] Output: [crayon-66376c8d87f05191143597/] You […]

  • 07 April

    Valueerror: Invalid literal for int() with base 10

    In this post, we will see about Valueerror: Invalid literal for int() with base 10. You will see this error, when you are trying to convert string to int using int() function. If you provide invalid string input to int() function, you will get this error. Here is the slider to understand it better. [smartslider3 […]

  • 07 April

    TypeError: String Indices Must be Integers

    In this post, we will see about TypeError: String Indices Must be Integers in Python. You can access the characters of string by its index. Each index specifies the position for the character. For example: Let’s say you want to print 3rd element of the String 'Java2blog', you can use str1[2]. [crayon-66376c8d88427825372690/] Output: v If […]

  • 05 April

    Local variable referenced before assignment

    In this post, we will see about error Local variable referenced before assignment in Python. Problem Let me explain this error with the help of an example. [crayon-66376c8d8859e713404959/] When you run above program, you will get below output: [crayon-66376c8d885a3197742914/] Let’s understand why we are getting this error UnboundLocalError. When Python interpreter parses any function definition […]