Posts for Python

Deven
Deven wrote

Fix – TypeError: only length-1 arrays can be converted to Python

If you are getting TypeError: only length-1 arrays can be converted to Python scalars error, this article will help you fix the issue. Consider the following example which throws you the same error Output of the above the Code. To fix TypeError: only length-1 arrays can be converted to Python scalars issue you need to convert […]

March 7, 2021 in Errors solved

How to Get Index of List Element in Python

In this article, you will learn how to get index of list element in Python. Let’s say you have a list of cardinal directions. directions = [‘North’, ‘South’, ‘East’, ‘West’] Get Index of List Element in Python In order to get the index of a list element, you can use the index() method. directions = […]

February 28, 2021 in Code examples

How to Do Hybrid Inheritance in Python

In this article, you will learn how to do hybrid inheritance in Python. Hybrid inheritance is a combination of multilevel inheritance and multiple inheritance. # This class is the base class class Father: def func1(self): print(“This function is in Father”) # This class inherits from Father class FirstChild(Father): def func2(self): print(“This function is in FirstChild”) […]

February 28, 2021 in Code examples

How to Refer to Base Class in Python

In this article, you will learn how to refer to base class in Python. Let’s say you have 2 classes, a base class named Father and a derived class named Son. class Father(object): def __init__(self, fatherGender): print(fatherGender, ‘is a male.’) class Son(Father): def __init__(self): print(‘Son is 20 years old.’) Refer to Base Class in Python […]

February 28, 2021 in Code examples

How to Use SimpleHTTPServer in Python

In this article, you will learn how to use SimpleHTTPServer in Python. SimpleHTTPServer is a built-in Python module that provides standard GET and HEAD requests. Use SimpleHTTPServer in Python In this example, you need to open up a command prompt (CMD) or Terminal and navigate to any directory. Then, type the following command in your […]

February 28, 2021 in Code examples

How to Join Tuples in Python

In this article, you will learn how to join tuples in Python. Let’s say you have 2 tuples. Join Tuples in Python In order to join tuples, you can use the zip() method and tuple() method. Note: The zip() method functions by creating a series of tuples from each element in both supplied iterables. The […]

February 26, 2021 in Code examples