pythonprogrammer pythonprogrammer - 1 year ago 115
Python Question

Python: Is there an equivalent of mid, right, and left from BASIC?

I want to do something like this:

>>> mystring = "foo"
>>> print(mid(mystring))


Answer Source

slices to the rescue :)

def left(s, amount):
    return s[:amount]

def right(s, amount):
    return s[-amount:]

def mid(s, offset, amount):
    return s[offset:offset+amount]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download