How to chain Python function calls so the behaviour is as follows

How to chain Python function calls so the behaviour is as follows

I stumbled upon the following problem on a python challenge: Write a function that satisfies the following rule for any number of function calls.

f()()()()()(s) == 'fooooo' + s;

example:

f('it') == 'fit';
f()('x') == 'fox';
f()()('bar') == 'foobar';
f()()()('l') == 'foool';

The function should be stateless and should not use any variables outside the scope.

The function signature was:

def f(s=None):
    # Your code here

I thought that in order to be able to chain multiple calls we will have to return a function when no string is passed into the function, but can't figure out how to build the expected string with no external variables. Suggestions?

def f(s=None):
    if s is None:
        # concatenate an 'o'?
        return f
    else:
        # Last call, return the result str.
        return s


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

Python GUI Programming Projects using Tkinter and Python 3

Python GUI Programming Projects using Tkinter and Python 3

Guide to Python Programming Language

Guide to Python Programming Language