The Wayback Machine - https://web.archive.org/web/20240912174110/https://www.geeksforgeeks.org/how-to-create-an-empty-class-in-python/
Open In App

How to create an empty class in Python?

Last Updated : 29 Dec, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

A class is a user-defined blueprint or prototype from which objects are created. Class can be considered as a user-defined data type. Generally, a class contains data members known as attributes of the class and member functions that are used to modify the attributes of the class. But have you ever wondered how to define an empty class i.e a class without members and member functions?

In Python, if we write something like the following, it would raise a SyntaxError.





Output:

  File "gfg.py", line 5

                ^
SyntaxError: unexpected EOF while parsing

In Python, to write an empty class pass statement is used. pass is a special statement in Python that does nothing. It only works as a dummy statement. However, objects of an empty class can also be created.

Example:





Output:

<__main__.Geeks object at 0x02B4A340>

Python also allows us to set the attributes of an object of an empty class. We can also set different attributes for different objects. See the following example for better understanding.





Output:

obj1 Details:
Name: Nikhil
Office: GeeksforGeeks

obj2 Details:
Name: Abhinav
Office: GeeksforGeeks
Phone: 1234567889
Traceback (most recent call last):
  File "gfg.py", line 34, in 
    print("Phone:", obj1.phone)
AttributeError: 'Employee' object has no attribute 'phone'

Previous Article
Next Article

Similar Reads

Python | Create an empty text file with current date as its name
In this article, we will learn how to create a text file names as the current date in it. For this, we can use now() method of datetime module. The datetime module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic is supported, the focus of the implementation is on efficient attribute
1 min read
How to Create an Empty Figure with Matplotlib in Python?
Creating a figure explicitly is an object-oriented style of interfacing with matplotlib. The figure is a basic building block of creating a plot as Matplotlib graphs our data on figures. This figure keeps track of all other components such as child axes, legends, title, axis, etc. Steps to create an empty figure : First, we import the matplotlib li
2 min read
How to create an empty matrix with NumPy in Python ?
The term empty matrix has no rows and no columns. A matrix that contains missing values has at least one row and column, as does a matrix that contains zeros. Numerical Python (NumPy) provides an abundance of useful features and functions for operations on numeric arrays and matrices in Python. If you want to create an empty matrix with the help of
3 min read
Create an empty file using Python
File handling is a very important concept for any programmer. It can be used for creating, deleting, and moving files, or to store application data, user configurations, videos, images, etc. Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on fi
3 min read
How to create an empty PyGame window?
Pygame window is a simple window like any other window, in which we display our game screen. It is the first task we do so that we can display our output onto something. Our main goal here is to create a window and keep it running unless the user wants to quit. To perform these tasks first we need to install pygame package and import some pre-defin
2 min read
Wand - Create empty image with background
In Python we can create solid backgrounds using Wand. We can use these backgrounds for further use in image. We can use these backgrounds in a backgroundless image to make it more attractive. This can be done by simply using Image() function and setting width, height and background parameter. Syntax : C/C++ Code with Image(width=&lt;i&gt;image_widt
1 min read
wxPython - Create empty window
wxPython is one of the most famous library in python for building GUI applications. In this first article of wxPython we will build an empty window using wxPython Library. Steps to create empty window : 1. Import wx in your code 2. Create wx.App object 3. Create object for wx.Frame 4. Show frame using Show() function C/C++ Code # Import wx module i
1 min read
Create empty dataframe in Pandas
The Pandas Dataframe is a structure that has data in the 2D format and labels with it. DataFrames are widely used in data science, machine learning, and other such places. DataFrames are the same as SQL tables or Excel sheets but these are faster in use.Empty DataFrame could be created with the help of pandas.DataFrame() as shown in below example:
1 min read
How to create an empty and a full NumPy array?
NumPy is a crucial library for performing numerical computations in Python. It offers robust array objects that enable efficient manipulation and operations on extensive datasets. Creating NumPy arrays is an essential process in scientific computing and data analysis. In this article, we will explore how to create both empty and full NumPy arrays,
3 min read
How to create an empty PySpark DataFrame ?
In this article, we are going to see how to create an empty PySpark dataframe. Empty Pysaprk dataframe is a dataframe containing no data and may or may not specify the schema of the dataframe. Creating an empty RDD without schema We'll first create an empty RDD by specifying an empty schema. emptyRDD() method creates an RDD without any data.createD
3 min read
Create Derived Class from Base Class Universally in Python
In object-oriented programming, the concept of inheritance allows us to create a new class, known as the derived class, based on an existing class, referred to as the base class. This facilitates code reusability and structuring. Python provides a versatile way to create derived classes from base classes universally, allowing for flexibility and sc
3 min read
How to write an empty function in Python - pass statement?
In C/C++ and Java, we can write empty function as following // An empty function in C/C++/Java void fun() { } In Python, if we write something like following in Python, it would produce compiler error. # Incorrect empty function in Python def fun(): Output : IndentationError: expected an indented block In Python, to write empty functions, we use pa
1 min read
String slicing in Python to check if a string can become empty by recursive deletion
Given a string “str” and another string “sub_str”. We are allowed to delete “sub_str” from “str” any number of times. It is also given that the “sub_str” appears only once at a time. The task is to find if “str” can become empty by removing “sub_str” again and again. Examples: Input : str = "GEEGEEKSKS", sub_str = "GEEKS" Output : Yes Explanation :
2 min read
Python | Remove empty tuples from a list
In this article, we will see how can we remove an empty tuple from a given list of tuples. We will find various ways, in which we can perform this task of removing tuples using various methods and ways in Python. Examples: Input : tuples = [(), ('ram','15','8'), (), ('laxman', 'sita'), ('krishna', 'akbar', '45'), ('',''),()]Output : [('ram', '15',
8 min read
Python | Remove and print every third from list until it becomes empty
Given a list of numbers, Your task is to remove and print every third number from a list of numbers until the list becomes empty. Examples: Input : [10, 20, 30, 40, 50, 60, 70, 80, 90] Output : 30 60 90 40 80 50 20 70 10 Explanation: The first third element encountered is 30, after 30 we start the count from 40 for the next third element which is 6
4 min read
Python | First Non-Empty String in list
Sometimes while dealing with data science, we need to handle a large amount of data and hence we may require shorthands to perform certain tasks. We handle the Null values at preprocessing stage and hence sometimes require to check for the 1st valid element. Let's discuss certain ways in which we can find the first Non-Empty String. Method #1 : Usi
5 min read
Python Program to Check if String is Empty or Not
Python strings are immutable and have more complex handling when discussing their operations. Note that a string with spaces is actually an empty string but has a non-zero size. This article also discussed that problem and the solution to it. Let's see different methods of Check if String is Empty Python. Example Input:[" "]Output: YesExplanation:
8 min read
Python | Remove empty strings from list of strings
In many scenarios, we encounter the issue of getting an empty string in a huge amount of data and handling that sometimes becomes a tedious task. Let's discuss certain way-outs to remove empty strings from list of strings. Method #1: Using remove() This particular method is quite naive and not recommended use, but is indeed a method to perform this
7 min read
Python | Pandas TimedeltaIndex.empty
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas TimedeltaIndex.empty attribute return a boolean value. It returns False if the TimedeltaIndex object on which it is applied is no
2 min read
Python | Pandas DataFrame.empty
Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. It can be thought of as a dict-like container for Series objects. This is the primary data structure of the Pandas. Pandas DataFrame.empty attribute che
2 min read
Python | Remove trailing empty elements from given list
Given a list, the task is to remove trailing None values from last of the list. Let's discuss a few methods to solve the given task. Examples: Input: [1, 2, 3, 4, None, 76, None, None] Output: [1, 2, 3, 4, None, 76] Input: [1, 2, None, None, None, None, None, 5] Output: [1, 2, None, None, None, None, None, 5] Method #1: Using naive method C/C++ Cod
7 min read
Python | Splitting list on empty string
Sometimes, we may face an issue in which we require to split a list to list of list on the blank character sent as deliminator. This kind of problem can be used to send messages or can be used in cases where it is desired to have list of list of native list. Let's discuss certain ways in which this can be done. Method #1 : Using index() and list sl
4 min read
Python | Check if dictionary is empty
Sometimes, we need to check if a particular dictionary is empty or not. In the web development domain in which we sometimes need to test for results of a particular query or check whether we have any key to add info into a database. Let's discuss certain ways in which this task can be performed in Python. Check if a Dictionary is Empty using bool()
6 min read
Python | Convert None to empty string
Sometimes, while working with Machine Learning, we can encounter None values and we wish to convert them to an empty string for data consistency. This and many other utilities can require a solution to this problem. Let's discuss certain ways in which this problem can be solved. Method #1: Using lambda This task can be performed using the lambda fu
5 min read
Python | Initialize list with empty dictionaries
While working with Python, we can have a problem in which we need to initialize a list of a particular size with empty dictionaries. This task has it's utility in web development to store records. Let's discuss certain ways in which this task can be performed. Method #1 : Using {} + "*" operator This task can be performed using the "*" operator. We
5 min read
Python | Check if any String is empty in list
Sometimes, while working with Python, we can have a problem in which we need to check for perfection of data in list. One of parameter can be that each element in list is non-empty. Let's discuss if a list is perfect on this factor using certain methods. Method #1 : Using any() + len() The combination of above functions can be used to perform this
6 min read
Python: Check if a directory is empty
Python is a widely used general-purpose, high-level programming language. It provides many functionalities and one among them is checking whether a directory is empty or not. This can be achieved by using os module. The OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules
2 min read
Python: Get List of all empty Directories
The OS module in Python is used for interacting with the operating system. This module comes with Python's standard utility module so there is no need to install it externally. All functions in the OS module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type but are not accepted
2 min read
Python | Empty String to None Conversion
Sometimes, while working with Machine Learning, we can encounter empty strings and we wish to convert to the None for data consistency. This and many other utilities can require the solution to this problem. Let’s discuss certain ways in which this problem can be solved. Method #1 : Using lambda This task can be performed using the lambda function.
4 min read
Python - Merge consecutive empty Strings
Sometimes, while working with python lists, we can have a problem in which we need to perform a merge operation on a string of lists. This merge is consecutive to convert multiple spaces to one. Let's discuss a certain way in which this can be performed. Method #1 : Using loop, This is a brute way in which this task can be performed. In this, we fi
6 min read