Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Post Closed as "exact duplicate" by Martijn Pieters, brandizzi, Pavel Anossov, joce, Javier
formatting
Source Link
Facundo Casco

Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1]instructions = f.readline()[:-1]

Have searched on here on S.O. and on Google but to no avail. Would love an explanation!

Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1]

Have searched on here on S.O. and on Google but to no avail. Would love an explanation!

Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1]

Have searched on here on S.O. and on Google but to no avail. Would love an explanation!

Source Link
Matt.

What does [:-1] mean/do in python?

Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1]

Have searched on here on S.O. and on Google but to no avail. Would love an explanation!

lang-py