Quick Question about Python concatenation

  • Context: Python 
  • Thread starter Thread starter NATURE.M
  • Start date Start date
  • Tags Tags
    Python
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
NATURE.M
Messages
298
Reaction score
0

Homework Statement



Lets say we have two strings 'movies' and ' goto'. Now the question indicates to return this combination concatenated n times, except if n is negative, it is the same as if it were 0.

The Attempt at a Solution



Concatenation n times would yield: n*"movies goto"

Now if n is negative it performs in the same way you would expect 0 to perform, so would that just return None ?
Like if n = 0, or n = -4 should it just return None?
 
Physics news on Phys.org
NATURE.M said:

Homework Statement



Lets say we have two strings 'movies' and ' goto'. Now the question indicates to return this combination concatenated n times, except if n is negative, it is the same as if it were 0.

The Attempt at a Solution



Concatenation n times would yield: n*"movies goto"

Now if n is negative it performs in the same way you would expect 0 to perform, so would that just return None ?
Like if n = 0, or n = -4 should it just return None?

Don't you have a python interpreter to try it out in? "None" would be a plausible answer, but I don't think it does that. It returns an empty string. Also plausible.
 
Dick said:
Don't you have a python interpreter to try it out in? "None" would be a plausible answer, but I don't think it does that. It returns an empty string. Also plausible.

I was mainly confused with the wording but I think I got it now. Your right it should return the empty string, instead of none. Thanks.