Why is the console printing '-' and '_' when it is instructed not to?

I have made a program which camel cases sentences. Also, it is instructed to not to print whitespaces, hyphens(-) and underscores(_).

The output which I had expected is


but what I am getting is mentioned below:


The same is happening in the case of underscore but not whitespace.

Therefore, I would like to know from the community where am I going wrong. Every suggestion will be appreciated.


lets resolve the comparison with word='-', the comparison is then:

# step one
if '-' != ' ' or '-' != '-' or '-' != '_': 

which resolves to:

#step two
if True or False or True:

which results in:

# step 3
print(True or False or True) # prints: True

oops? That doesn’t seem like the desired outcome

see if you can figure out how to correct this, or let me know if you need more help.

1 Like

I can’t imagine that the split() function would automatically remove a ‘-’ or ‘_’, or treat those as a separator without some instruction?

Therefore I think it likely that ‘hello-world’ is being treated as a single string by the split() function.

Your chosen separator needs to be provided to the split() function. To do that with multiple separator characters is going to require some further thinking.