There are several interacting considerations here:

  1. failure inside __init__ fails to construct the object
  2. re-use of code
  3. clear organisation and documentation of code
  4. minor code differences such as using an attribute instead of a local

Separation of create_snake into it's own method (#3), with a name that documents it's purpose, clarifies and organises the code to make it quicker to understand and modify and potentially more robust (in principle, possibly of negligible difference in this case). Identifier names are arguably the single most important element of code documentation, in this case "create snake". I think this is a good argument for using snake case identifiers.

At this point in the development there's no indication whether create_snake will be called at any other time for this object, but if later you do need to create_snake again, for the same object, this separation of the create_snake code keeps it DRY (#2).

In Python, __init__ always returns None. It's not a "proper" method from that point of view. Any failures inside the __init__ method will mean the object is not created, potentially requiring a try...except wrapper (#1). Work should be minimised within __init__ (#1) for this reason.

In your implementation here, moving the code out into create_snake doesn't actually fix that, because it's still called from __init__. This can be improved by calling create_snake after the object is created, but that slightly complicates the usage pattern, and may not be justified in this instance (depends on your planning).

(The reason I found this question in the first place was because I was seeking clarification of a vague memory I have of some article arguing that doing work inside __init__ is an anti-pattern.)

To take this concept even further, you can create a practically empty object, and leave snake creation, and any other work, to lazy methods that are only called when needed. You can find further discussion on approaches.

There are other code considerations that may possibly be incidental to your core question (#4). For instance, there's no point in using an instance attribute (self.snake_segment) when you never use that value after the method completes, because it just makes the object heavier and requires more variable look-ups. Depending on your wider code organisation, it may also be better to keep class related constants (STARTING_POSITIONS) inside the class, rather than at the module level. I'm not stating that is the case for you; it depends very much on what your wider code is doing.

As an overall answer I'd say that your second approach is definitely better, and most probably good enough as well.

Answer from NeilG on Stack Overflow
Top answer
1 of 1
2

There are several interacting considerations here:

  1. failure inside __init__ fails to construct the object
  2. re-use of code
  3. clear organisation and documentation of code
  4. minor code differences such as using an attribute instead of a local

Separation of create_snake into it's own method (#3), with a name that documents it's purpose, clarifies and organises the code to make it quicker to understand and modify and potentially more robust (in principle, possibly of negligible difference in this case). Identifier names are arguably the single most important element of code documentation, in this case "create snake". I think this is a good argument for using snake case identifiers.

At this point in the development there's no indication whether create_snake will be called at any other time for this object, but if later you do need to create_snake again, for the same object, this separation of the create_snake code keeps it DRY (#2).

In Python, __init__ always returns None. It's not a "proper" method from that point of view. Any failures inside the __init__ method will mean the object is not created, potentially requiring a try...except wrapper (#1). Work should be minimised within __init__ (#1) for this reason.

In your implementation here, moving the code out into create_snake doesn't actually fix that, because it's still called from __init__. This can be improved by calling create_snake after the object is created, but that slightly complicates the usage pattern, and may not be justified in this instance (depends on your planning).

(The reason I found this question in the first place was because I was seeking clarification of a vague memory I have of some article arguing that doing work inside __init__ is an anti-pattern.)

To take this concept even further, you can create a practically empty object, and leave snake creation, and any other work, to lazy methods that are only called when needed. You can find further discussion on approaches.

There are other code considerations that may possibly be incidental to your core question (#4). For instance, there's no point in using an instance attribute (self.snake_segment) when you never use that value after the method completes, because it just makes the object heavier and requires more variable look-ups. Depending on your wider code organisation, it may also be better to keep class related constants (STARTING_POSITIONS) inside the class, rather than at the module level. I'm not stating that is the case for you; it depends very much on what your wider code is doing.

As an overall answer I'd say that your second approach is definitely better, and most probably good enough as well.

🌐
Medium
medium.com › @robsonsampaio90 › snake-game-in-python-with-pygame-291f5206a35e
Snake Game in Python with Pygame. Hi, this article will show you how to… | by Robson Sampaio | Medium
May 24, 2020 - Well, if you are familiar with python and OOP you will see that I just created a class called Snake and also created a constructor which is the method __init__
Discussions

I wrote a Snake game in pure Python!
r/madeinpython for bragging rights. Unless you have some questions about it or want code critique? More on reddit.com
🌐 r/learnpython
11
63
October 19, 2020
what are constructors in python?
Construction is implicit in python, __init__ is used for initialization of a new object. There is a __new__ constructor, but you'll likely not need to write one ever. https://docs.python.org/3/reference/datamodel.html#classes 3.2.8.8. Classes Classes are callable. These objects normally act as factories for new instances of themselves, but variations are possible for class types that override __new__() . The arguments of the call are passed to __new__() and, in the typical case, to __init__() to initialize the new instance. More on reddit.com
🌐 r/learnpython
23
11
June 30, 2025
🌐
Towards Data Science
towardsdatascience.com › home › latest › implementing the snake game in python
Implementing the Snake Game in Python | Towards Data Science
February 12, 2026 - Note that this is a beginners to intermediate level Python tutorial, and expects the reader to be familiar with Python fundamentals such as functions and loops, importing and accessing modules, and using conditional statements. It also requires one to have a surface-level understanding of Object Oriented Programming, especially creating objects instances from classes. For the sake of simplicity, I will explain each and every line of code. Let’s get started! ... The classical Snake game involves a small snake with a plain background.
🌐
GitHub
gist.github.com › wynand1004 › ec105fd2f457b10d971c09586ec44900
A Simple Snake Game made in Python 3 · GitHub
Nice game, you can create classes for the snake body, scoreboard, food and maybe wall. Then the code will be more structured :) ... /bin/python3 "/home/devil/Code/Python/Turtle/Snake Game/snake_game.py" Traceback (most recent call last): File "/home/devil/Code/Python/Turtle/Snake Game/snake_game.py", line 4, in <module> import turtle File "/usr/lib/python3.10/turtle.py", line 107, in <module> import tkinter as TK ModuleNotFoundError: No module named 'tkinter'
🌐
Pythonspot
pythonspot.com › snake-with-pygame
python snake game - Python Tutorial
Python hosting: Host, run, and code Python in the cloud! In this tutorial you will learn how to build the game snake.
🌐
GeeksforGeeks
geeksforgeeks.org › python › create-a-snake-game-using-turtle-in-python
Create a Snake-Game using Turtle in Python - GeeksforGeeks
February 18, 2026 - The Snake Game is a classic arcade game first released in 1976 by Gremlin Industries and published by Sega. The goal is simple to control the snake using arrow keys, collect food to grow longer and avoid hitting the walls or yourself. We’ll build this game in Python using the following modules:
🌐
Edureka
edureka.co › blog › snake-game-with-pygame
How To Write Python Code for Snake Game using Pygame?
March 11, 2025 - Snake Game in Python using Pygame which is free and open-source Python library used to create games.Create snake,add food,increase snakesize,score,etc.
Find elsewhere
🌐
Python Engineer
python-engineer.com › posts › snake-game-in-python
Snake Game In Python - Python Beginner Tutorial - Python Engineer
import curses from random import randint # setup window curses.initscr() win = curses.newwin(20, 60, 0, 0) # y,x win.keypad(1) curses.noecho() curses.curs_set(0) win.border(0) win.nodelay(1) # -1 # snake and food snake = [(4, 10), (4, 9), (4, 8)] food = (10, 20) win.addch(food[0], food[1], '#') # game logic score = 0 ESC = 27 key = curses.KEY_RIGHT while key != ESC: win.addstr(0, 2, 'Score ' + str(score) + ' ') win.timeout(150 - (len(snake)) // 5 + len(snake)//10 % 120) # increase speed prev_key = key event = win.getch() key = event if event != -1 else prev_key if key not in [curses.KEY_LEFT,
🌐
Medium
medium.com › @sjalexandre › python-tutorial-building-the-game-snake-d9f88595a64b
Python Tutorial — Building the Game Snake | Medium
August 15, 2023 - Apply core programming concepts and game development fundamentals to develop the classic game Snake in Python.
🌐
GitHub
gist.github.com › sanchitgangwar › 2158089
Snakes Game using Python · GitHub
Snakes Game using Python. GitHub Gist: instantly share code, notes, and snippets.
🌐
GeeksforGeeks
geeksforgeeks.org › python › constructors-in-python
Constructors in Python - GeeksforGeeks
July 11, 2025 - In Python, a constructor is a special method that is called automatically when an object is created from a class.
🌐
GitHub
github.com › topics › constructor
constructor · GitHub Topics · GitHub
python food object class inheritance snake snake-game scoreboard constructor · Updated · Jun 28, 2024 · Python · Star 1 · Python is an object oriented programming language. Unlike procedure oriented programming, where the main emphasis is on functions, object oriented programming stress on objects.
Top answer
1 of 5
115

There is no function overloading in Python, meaning that you can't have multiple functions with the same name but different arguments.

In your code example, you're not overloading __init__(). What happens is that the second definition rebinds the name __init__ to the new method, rendering the first method inaccessible.

As to your general question about constructors, Wikipedia is a good starting point. For Python-specific stuff, I highly recommend the Python docs.

2 of 5
66

Why are constructors indeed called "Constructors" ?

The constructor (named __new__) creates and returns a new instance of the class. So the C.__new__ class method is the constructor for the class C.

The C.__init__ instance method is called on a specific instance, after it is created, to initialise it before being passed back to the caller. So that method is the initialiser for new instances of C.

How are they different from methods in a class?

As stated in the official documentation __init__ is called after the instance is created. Other methods do not receive this treatment.

What is their purpose?

The purpose of the constructor C.__new__ is to define custom behaviour during construction of a new C instance.

The purpose of the initialiser C.__init__ is to define custom initialisation of each instance of C after it is created.

For example Python allows you to do:

class Test(object):
    pass

t = Test()

t.x = 10   # here you're building your object t
print t.x

But if you want every instance of Test to have an attribute x equal to 10, you can put that code inside __init__:

class Test(object):
    def __init__(self):
        self.x = 10

t = Test()
print t.x

Every instance method (a method called on a specific instance of a class) receives the instance as its first argument. That argument is conventionally named self.

Class methods, such as the constructor __new__, instead receive the class as their first argument.

Now, if you want custom values for the x attribute all you have to do is pass that value as argument to __init__:

class Test(object):
    def __init__(self, x):
        self.x = x

t = Test(10)
print t.x
z = Test(20)
print t.x

I hope this will help you clear some doubts, and since you've already received good answers to the other questions I will stop here :)

🌐
Real Python
realpython.com › python-class-constructor
Python Class Constructors: Control Your Object Instantiation – Real Python
January 19, 2025 - In Python, when you call a class as you did in the above example, you’re calling the class constructor, which creates, initializes, and returns a new object by triggering Python’s internal instantiation process.
🌐
Devcamp
bottega.devcamp.com › full-stack-development-javascript-python › guide › guide-pythons-__init__-constructor-function
Guide to Python's __init__ Constructor Function
With that in place, we can now call the files so Python invoice and there you go printed out perfectly. Google owes 100 dollars and SnapChat owes 200 hundred dollars. Let's review exactly what's going on here. So we have created a class from there we created a constructor function so we used the Dunder init function here we passed in self so we have access to the instance of the class.
🌐
Edureka
edureka.co › blog › python-constructors
Python Constructors | How To Implement Constructors In Python | Edureka
November 28, 2024 - Once the __init__ function has ... upon your needs. The most common use of a constructor in Python is to initialize the attributes of a class....
🌐
Reddit
reddit.com › r/learnpython › i wrote a snake game in pure python!
r/learnpython on Reddit: I wrote a Snake game in pure Python!
October 19, 2020 -

Hi everyone,

I'm a grad student who's been learning/using Python for about two years now. As a "toy project" to challenge myself, I've put together a Snake game in pure Python - no dependencies, no pygame, only the standard library. I know it's small, and it's been done a thousand times over, but I'm proud of how it has turned out.

Python was my first programming language ever, which I decided to learn out of the need for automation in my PhD analyses. I've since fallen in love with programming and data analysis. Hopefully this will encourage some of you to keep on learning :-) don't give up!

Feel free to see it in action and get the code here:

https://github.com/jfaccioni/python-snake-game

🌐
Python Guides
pythonguides.com › constructor-in-python
How to Use Constructors in Python?
March 9, 2026 - Learn how to use constructors in Python with detailed examples and best practices. Understand syntax, class initialization, and constructor overriding to write efficient and maintainable code.