There are several ways to assign the equal variables.

The easiest one:

grade_1 = grade_2 = grade_3 = average = 0.0

With unpacking:

grade_1, grade_2, grade_3, average = 0.0, 0.0, 0.0, 0.0

With list comprehension and unpacking:

>>> grade_1, grade_2, grade_3, average = [0.0 for _ in range(4)]
>>> print(grade_1, grade_2, grade_3, average)
0.0 0.0 0.0 0.0
Answer from sobolevn on Stack Overflow
🌐
Python
docs.python.org › 3 › c-api › init_config.html
Python Initialization Configuration — Python 3.14.3 documentation
PyInitConfig C API: Python can be initialized with Py_InitializeFromInitConfig(). The Py_RunMain() function can be used to write a customized Python program. See also Initialization, Finalization, ...
🌐
Python.org
discuss.python.org › python help
What is initialization in python? - Python Help - Discussions on Python.org
July 10, 2024 - The concept of initialization doesn’t even technically exist, or at least the way initialization is described for static typed languages like C++. Source: "Initializing" variables in python? - Stack Overflow It’ all assignment but I find people do use colloquially initialization to mean first assignment.
Discussions

Can someone explain why I need to initialize a class?
Simple answer: you don't. There's no requirement to have an init method. It's just that most of the time the first thing we do when making a new instance is to run some setup code, so the init method is a convenient place to put that. More on reddit.com
🌐 r/learnpython
28
67
September 13, 2021
Understanding classes, init and self
Could you explain this code excerpt? I am learning and trying to get in touch with the logic of classes · The __init__ method initialises a new instance (object) of the class NewWindow. The actual creation of the instance is done by a separate method __new__, before __init__ is called. More on discuss.python.org
🌐 discuss.python.org
19
0
February 16, 2024
Top answer
1 of 7
23

There are several ways to assign the equal variables.

The easiest one:

grade_1 = grade_2 = grade_3 = average = 0.0

With unpacking:

grade_1, grade_2, grade_3, average = 0.0, 0.0, 0.0, 0.0

With list comprehension and unpacking:

>>> grade_1, grade_2, grade_3, average = [0.0 for _ in range(4)]
>>> print(grade_1, grade_2, grade_3, average)
0.0 0.0 0.0 0.0
2 of 7
21

I know you have already accepted another answer, but I think the broader issue needs to addressed - programming style that is suitable to the current language.

Yes, 'initialization' isn't needed in Python, but what you are doing isn't initialization. It is just an incomplete and erroneous imitation of initialization as practiced in other languages. The important thing about initialization in static typed languages is that you specify the nature of the variables.

In Python, as in other languages, you do need to give variables values before you use them. But giving them values at the start of the function isn't important, and even wrong if the values you give have nothing to do with values they receive later. That isn't 'initialization', it's 'reuse'.

I'll make some notes and corrections to your code:

def main():
   # doc to define the function
   # proper Python indentation
   # document significant variables, especially inputs and outputs
   # grade_1, grade_2, grade_3, average - id these
   # year - id this
   # fName, lName, ID, converted_ID 

   infile = open("studentinfo.txt", "r") 
   # you didn't 'intialize' this variable

   data = infile.read()  
   # nor this  

   fName, lName, ID, year = data.split(",")
   # this will produce an error if the file does not have the right number of strings
   # 'year' is now a string, even though you 'initialized' it as 0

   year = int(year)
   # now 'year' is an integer
   # a language that requires initialization would have raised an error
   # over this switch in type of this variable.

   # Prompt the user for three test scores
   grades = eval(input("Enter the three test scores separated by a comma: "))
   # 'eval' ouch!
   # you could have handled the input just like you did the file input.

   grade_1, grade_2, grade_3 = grades   
   # this would work only if the user gave you an 'iterable' with 3 values
   # eval() doesn't ensure that it is an iterable
   # and it does not ensure that the values are numbers. 
   # What would happen with this user input: "'one','two','three',4"?

   # Create a username 
   uName = (lName[:4] + fName[:2] + str(year)).lower()

   converted_id = ID[:3] + "-" + ID[3:5] + "-" + ID[5:]
   # earlier you 'initialized' converted_ID
   # initialization in a static typed language would have caught this typo
   # pseudo-initialization in Python does not catch typos
   ....
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python __init__: an overview
Python __init__: An Overview
October 14, 2024 - In Python, __init__ is a special method known as the constructor. It is automatically called when a new instance (object) of a class is created. The __init__ method allows you to initialize the attributes (variables) of an object.
🌐
GeeksforGeeks
geeksforgeeks.org › python › __init__-in-python
__init__ in Python - GeeksforGeeks
__init__ method in Python is a constructor. It runs automatically when a new object of a class is created. Its main purpose is to initialize the object’s attributes and set up its initial state.
Published   September 12, 2025
🌐
Python
docs.python.org › 3 › c-api › init.html
Initialization, finalization, and threads — Python 3.14.3 documentation
This page has been split up into the following: Interpreter initialization and finalization, Thread states and the global interpreter lock, Synchronization primitives, Thread-local storage support,...
🌐
LabEx
labex.io › tutorials › python-how-to-initialize-data-in-a-python-class-417302
How to initialize data in a Python class | LabEx
The syntax for defining a Python class is as follows: class ClassName: """Class docstring""" class_attribute = value def __init__(self, param1, param2, ...): self.attribute1 = param1 self.attribute2 = param2 ## other initialization logic def method1(self, arg1, arg2, ...): ## method implementation def method2(self, arg1, arg2, ...): ## method implementation
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › can someone explain why i need to initialize a class?
r/learnpython on Reddit: Can someone explain why I need to initialize a class?
September 13, 2021 -

Trying to get more into classes and I do not understand the init method or self. Any ELIF?

Edit: maybe a better question is what is the downside to not initializing a class/variables

🌐
StrataScratch
stratascratch.com › blog › what-is-the-purpose-of-__init__-in-python
What Is the Purpose of __init__ in Python? - StrataScratch
November 7, 2024 - The __init__ method in Python initializes an object's attributes at creation, setting up each instance with specific values to keep code organized and scalable.
🌐
Analytics Vidhya
analyticsvidhya.com › home › all about init in python
All About init in Python - Analytics Vidhya
February 1, 2024 - It is a special method automatically called when an object is created from a class. This method allows us to initialize an object’s attributes and perform any necessary setup or initialization tasks.
🌐
Sourceforge
protoframework.sourceforge.io › articles › article_pythoninitsequence.html
Python initialization and runtime sequence - Home
The runtime phase: this phase takes place after the module start Note that if the initialization phase does not end correctly[1] It can be the case if the Python script takes too much time to start-up, or if there is an exception during the initialization of the script , then the Python module ...
🌐
Python
peps.python.org › pep-0587
PEP 587 – Python Initialization Configuration | peps.python.org
Python is highly configurable but its configuration evolved organically. The initialization configuration is scattered all around the code using different ways to set them: global configuration variables (ex: Py_IsolatedFlag), environment variables (ex: PYTHONPATH), command line arguments (ex: -b), configuration files (ex: pyvenv.cfg), function calls (ex: Py_SetProgramName()).
🌐
Edureka
edureka.co › blog › init-in-python
Init In Python | Python Init Class | What is Init Function | Edureka
November 27, 2024 - __init__ is one of the reserved methods in Python. In object oriented programming, it is known as a constructor. The __init__ method can be called when an object is created from the class, and access is required to initialize the attributes ...
🌐
Real Python
realpython.com › videos › obj-declaration-initilization
Declaration and Initialization (Video) – Real Python
Those fields are then initialized in the constructor. 00:46 The constructor takes three parameters—car, model, and year—and since we’ve used the same names as the names of our fields, we have to use the word this when referring to the field to prevent the ambiguity. So we say this.color = color, this.model = model, this.year = year. 01:09 In Python, the declaration and initialization happen simultaneously in an .__init__() method.
Published   June 4, 2021
🌐
Medium
ishanjainoffical.medium.com › understanding-pythons-init-method-object-initialization-in-depth-cc16f6e1e322
Understanding Python’s init Method: Object Initialization in Depth | by Data Science & Beyond | Medium
October 1, 2023 - It allows you to set up the initial state or attributes of an object. Python __init__ is used to ensure that when you create an object from a class (like creating a toy or a car from a blueprint), it starts with the right characteristics or ...
🌐
Udacity
udacity.com › blog › 2021 › 11 › __init__-in-python-an-overview.html
__init__ in Python: An Overview | Udacity
May 10, 2022 - The __init__ method is the Python equivalent of the C++ constructor in an object-oriented approach. The __init__ function is called every time an object is created from a class. The __init__ method lets the class initialize the object’s attributes ...
🌐
W3Schools
w3schools.com › python › gloss_python_class_init.asp
Python __init__() Function
To understand the meaning of classes we have to understand the built-in __init__() method. All classes have a method called __init__(), which is always executed when the class is being initiated.
🌐
Copahost
copahost.com › home › init python: learn how to use __init__ to initialize objects in python
init python: Learn how to use __init__ to initialize objects in python - Copahost
August 29, 2023 - The method __init__ is a special method in Python that is called automatically when creating a new instance of a class. We use this method to initialize the instance and it can be used to perform any action before the instance is applied.
🌐
Quora
quora.com › In-Python-programming-what-does-it-mean-to-initialize-all-the-variables
In Python programming, what does it mean to initialize all the variables? - Quora
Answer (1 of 5): Since Python variables and attributes are only created on assignment, conditional or delayed assignment may result in missing variables or attributes. The [code ]NameError[/code] and [code ]AttributeError[/code] are symptoms of someone forgetting to initialise expected names and ...