Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does :-1 mean in python? [duplicate]

Tags:

People also ask

What does 1 :] do in Python?

It selects all but the last element of a sequence.

What is meant in list A [- 1 in Python?

[-1] means the last element in a sequence, which in this is case is the list of tuples like (element, count) , order by count descending so the last element is the least common element in the original collection.

What does [:- 1 :] mean in Python?

What does [:-1] in Python actually do and why would you want to use it? [:-1] in Python is a slice operation used on strings or lists and captures all contents of the string or list except for the last character or element.


Possible Duplicate:
The Python Slice Notation

I'm trying to port some Python code to C, but I came across this line and I can't figure out what it means:

if message.startswith('<stream:stream'):     message = message[:-1] + ' />' 

I understand that if 'message starts with <stream:stream then something needs to be appended. However I can't seem to figure out where it should be appended. I have absolutely no idea what :-1 indicates. I did several Google searches with no result.

Would somebody be so kind as to explain what this does?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!