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]
Answer from Andy W on Stack Overflowslices 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]
If I remember my QBasic, right, left and mid do something like this:
>>> s = '123456789'
>>> s[-2:]
'89'
>>> s[:2]
'12'
>>> s[4:6]
'56'
http://www.angelfire.com/scifi/nightcode/prglang/qbasic/function/strings/left_right.html
Why does Python prefer the right side to the left side?
How do I align/move text right?
Videos
My question is pretty simple.
Code - 1:
print(False or None)
Output:
None
Code - 2:
print(None or False)
Output:
False
Why does the python interpreter prefer the right side to the left?
Hi all! So I’ve been trying to learn python by giving myself small tasks to do and I decided I wanted to make a right aligned right triangle (I know it’s really specific) but it never works, I’ve tried a few different things but I am never able to align it to the right, it always aligns left I have everything else correct though
*
**
***
****
*****Is what it’s supposed to look like
for a in range (-1, -6, -1):
for b in range (a, 0):
print ("*",end="")
print ("")There is my code, if someone could guide me on what I’m doing wrong/ how to fix it I’d be super grateful!
Sorry for formatting, am on mobile