Is there a strict comparison operator like === in Python?
📁 Advanced Python Topics, work
Just a regular comparison using == doesn't work as needed:
>>> 0 == FalseTrue You can use a special Python notation that allows accessing elements from the end of a list using negative indices. In this case, the slice [:-1] takes all elements from the list except the last one (minus first in Python's paradigm).
a = 'First - second - third'print('-'.join(a.split('-')[:-1]))Output:
First - second Log in to leave an answer
Blogs