Creating Python Logo using Python 😍

Ranvir Singh · 6 mins read ·
python beginners

Creating Python Logo using Python
We are going to print the Python shaped logo using Python colors. Our output is going to look something like this.

Python logo using characters
Let’s get started.

Install dependencies

The only dependency we have for this is colorama. It is used to show text with different colors. For example, if you want to show something really important in the code, you can show it using red.

colorama red color
We can simply install this using pip.

pip install colorama

Defining characters to color

We have to define a good length of characters so that we can print the logo with as much space as we want.

fgh ="""ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"""

Defining the data structure for the shape

We will define the data structure with color change information in a dictionary. This will contain information about the colors that we are going to use to print the character color logo.

final_dict = {
    # row: { "column with color change": "color after this coloum"...}
    "0": {
        "9": Fore.CYAN,
        "16": Fore.BLACK
    },
    "1": {
        "6": Fore.CYAN,
        "19": Fore.BLACK
    },
    "2": {
        "6": Fore.CYAN,
        "8": Fore.BLACK,
        "10": Fore.CYAN,
        "19": Fore.BLACK
    },
    "3": {
        "6": Fore.CYAN,
        "19": Fore.BLACK
    },
    "4": {
        "6": Fore.CYAN,
        "19": Fore.BLACK
    },
    "5": {
        "2": Fore.CYAN,
        "19": Fore.YELLOW,
        "23": Fore.BLACK
    },
    "6": {
        "1": Fore.CYAN,
        "19": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "7": {
        "1": Fore.CYAN,
        "19": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "8": {
        "1": Fore.CYAN,
        "19": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "9": {
        "1": Fore.CYAN,
        "11": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "10": {
        "1": Fore.CYAN,
        "9": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "11": {
        "1": Fore.CYAN,
        "9": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "12": {
        "2": Fore.CYAN,
        "11": Fore.YELLOW,
        "24": Fore.BLACK
    },
    "13": {
        "3": Fore.CYAN,
        "9": Fore.YELLOW,
        "23": Fore.BLACK
    },
    "14": {
        "6": Fore.YELLOW,
        "19": Fore.BLACK
    },
    "15": {
        "6": Fore.YELLOW,
        "19": Fore.BLACK
    },
    "16": {
        "6": Fore.YELLOW,
        "15": Fore.BLACK,
        "17": Fore.YELLOW,
        "19": Fore.BLACK
    },
    "17": {
        "7": Fore.YELLOW,
        "18": Fore.BLACK
    }
}
Please use Fore.WHITE if you are not using dark mode and please tell me why aren’t you using the dark mode.

Don’t worry if this doesn’t make any sense as of now. You will see the usage just in a second.

Color the characters

def get_dict_color(row, column, last_color):
    row = str(row)
    column = str(column)
    if final_dict.get(row).get(column):
        return final_dict.get(row).get(column)
    return last_color

row = 0
last_color = Fore.BLACK
for b in fgh.split('\n'):
    column = 0
    for c in b:
        last_color = get_dict_color(row, column, last_color)
        print(last_color + c, end="")
        column += 1
    print('\n', end="")
    row += 1
    if row == 18:
        break
This is a pretty simple Python code that is used to color the characters. In this code, we are looping over fgh variables which contain all the characters.

In each row of characters for each column of characters, we are calling the get_dict_color function which either returns the new color if the color is changing according to the defined data structure or returns the last color, we were using.

Run the program. You will get a Python logo of your own.

There might be a lot of implementations that we can use to print something like this, and we would like to hear about it in the comments below.

Please subscribe to the newsletter, if you want to read similar stories every week. Also, we would love to hear your Python story.

About Author

Ranvir Singh

Greetings! Ranvir is an Engineering professional with 3+ years of experience in Software development.

Please share your Feedback:

Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!