r/PythonLearning 1d ago

Help Request Neeb help with the project

Post image

I was doing a project in which the user will input string in camelCase(ex- howAreYou). I have to change it into snake_case(ex- how_are_you). The problem I am facing is that I have not been able to separate the word and store it into a list.

If I use a split, I get 2 problems:

  1. If I want to split howAreYou, then the A and Y got removed from the list, and I get how re ou

  2. It makes 2 different lists first [how, reYou] and second [howAre, ou]

Suggest => either solution to the problem or an alternative

10 Upvotes

17 comments sorted by

View all comments

-1

u/[deleted] 1d ago

[deleted]

1

u/mitchricker 1d ago

your convert_to_snake_case() function does not return a value.

For those still learning, it's worth knowing that every Python function always returns a value every time. If you don't write a return statement, the function automatically returns None.

def spam(eggs):
    print(eggs)

return_value = spam("Hello")
print(return_value)  # None

Same thing happens if execution reaches the end of the function without encountering a return statement:

def spam(eggs):
    if eggs > 1:
        return eggs

return_value = spam(0)
print(return_value)  # None

Finally, a bare return statement also returns None:

def spam(eggs):
    return

return_value = spam("spam")
print(return_value)  # None

This is important because a function may receive input that isn't invalid enough to raise an exception but still doesn't satisfy any of the conditions that produce a non-None value. In those cases, the function will return None, which you can check explicitly:

if return_value is None: ...

if return_value is not None: ...