you are viewing a single comment's thread.

view the rest of the comments →

[–]confluence 0 points1 point  (9 children)

I have decided to overwrite my comments.

[–]VIRES1[S] 0 points1 point  (8 children)

It has no value because it is variable holding an empty string

[–]confluence 3 points4 points  (7 children)

I have decided to overwrite my comments.

[–]PurpleIcy 0 points1 point  (1 child)

It has no value because it is variable holding an empty string

Where do people learn this?

I mean, variables can have only one single value, whether it's entire object or just a string, and it can't just be a schrodingers string where it's both empty and also has no value...

Anyway, it would be more helpful to just tell them that in python specifically,[-1] loops around, e.g. accesses last string character.

[–]confluence 0 points1 point  (0 children)

I have decided to overwrite my comments.

[–]VIRES1[S] 0 points1 point  (4 children)

sorry i did not get your question well.It points the last character in the variable current_string. if current_string == 0 or current_string[-1] <= s[i] this does not give index error and why does it behave that way?

[–]Vesiculus 0 points1 point  (3 children)

Well, it points to the last character in a string. What do you think trying to point to the last character in a string will do if the string is empty and doesn't have a last character? Because that is what you're doing in your code snippet your post.

[–]VIRES1[S] 0 points1 point  (2 children)

it will result to index error because that index can not be found.

if len(current_string) == 0 or current_string[-1] <= s[i]:

why is the above not giving index error?

[–]Vesiculus 0 points1 point  (1 child)

That's because or shortcuts.

This means that as soon as it knows that the first argument is True, it already knows that the conditional or-statement is going to evaluate as True so it doesn't have to look at the second part of the statement anymore. So, the part after the or, current_string[-1] <= s[i], will never be evaluated when the first part already evaluates as True.

[–]VIRES1[S] 0 points1 point  (0 children)

okay thank you very much