Python Forum
str.endswith(): vague documentation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
str.endswith(): vague documentation
#1
reading up on str.endswith() i find the optional arguments start and end to be described vaguely. it does not say how they apply, like whether they affect both strings at the same time or just one of them. and if they apply to the string in argument 1, does the end of its substring always get checked as if it was located with end at the end?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
>>> s = 'spam ham eggs'
>>> s.endswith('ham', None, 8)
True
>>> s.endswith('ham', 3, 8)
True
I would guess that s.endswith(x, start, stop) gives the same result as s[start:stop].endswith(x) but it saves the creation of a str instance.
Reply
#3
that was one of the guesses i had. but the documentation does not give enough clue to pin that down or confirm it. is saving the creation of a string instance considered important in a system where performance considerations are generally limited (to use the correct algorithm)?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
The endswith() method returns True if a string ends with the given suffix otherwise returns False.

Syntax :

str.endswith(suffix, start, end)
Reply
#5
(Nov-22-2019, 05:29 AM)LeanbridgeTech Wrote: The endswith() method returns True if a string ends with the given suffix otherwise returns False.

Syntax :

str.endswith(suffix, start, end)

even if start and end have random int values in those argument positions?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020