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 Overflow
🌐
Dot Net Perls
dotnetperls.com › right-python
Python - String Right Part - Dot Net Perls
December 13, 2021 - Consider the string "soft orange cat." The last 3 characters are "cat," and so the result of right() with an argument of 3 should be "cat." ... Here we introduce a "right" method. Pay close attention to the return value of right().
Discussions

Why does Python prefer the right side to the left side?
Because the operator “or” works like this: if the first item is true (or evaluates to true), return it otherwise, return the second item More on reddit.com
🌐 r/Python
37
67
August 7, 2023
How do I align/move text right?
Spaces = 12 For i in range(1,13): Print(" " * (spaces-i) + "*" * i) More on reddit.com
🌐 r/learnpython
13
3
June 9, 2020
🌐
Note.nkmk.me
note.nkmk.me › home › python
Right-justify, Center, Left-justify Strings and Numbers in Python | note.nkmk.me
May 18, 2023 - Use the rjust(), center(), or ljust() methods to right-justify, center, or left-justify strings str in Python. You can convert numbers (int and float) to strings using str() and apply these methods. R ...
🌐
Trymito
trymito.io › excel-to-python › functions › text › RIGHT
Excel to Python: RIGHT Function - A Complete Guide | Mito
Excel's RIGHT function is used to extract a specific number of characters from the right end of a text string. This can be especially useful in data preprocessing tasks like extracting the last name from a full name or extracting a unit label ...
🌐
W3Schools
w3schools.com › python › ref_string_rjust.asp
Python String rjust() Method
Note: In the result, there are actually 14 whitespaces to the left of the word banana. The rjust() method will right align the string, using a specified character (space is default) as the fill character.
🌐
STEMpedia
ai.thestempedia.com › home › python functions › right()
right() - Motion Library - Python Function
July 25, 2022 - right() function is from Motion library of PictoBlox Python. The function turns the sprite by the specified amount of degrees clockwise. This changes the direction the sprite is facing.
Find elsewhere
🌐
InterviewQs
interviewqs.com › ddi-code-snippets › substring-python
Slice a string in python (right, left, mid equivalents) - InterviewQs
Interview Questions Pricing Sign in · Back to snippets · import pandas as pd · Create some dummy data · string = '8754321' string · '8754321' #right 2 characters string[-2:] '21' #left 2 characters string[:2] '87' #4th through 6th characters (index starts at 0) string[4:6] '32'
🌐
Tutorialspoint
tutorialspoint.com › python › string_rjust.htm
Python String rjust() Method
Following is the syntax for Python String rjust() method − ... This method returns the string right justified in a string of length width. Padding is done using the specified fillchar (default is a space).
🌐
GeeksforGeeks
geeksforgeeks.org › python-right-and-left-shift-characters-in-string
Python - Right and Left Shift characters in String - GeeksforGeeks
April 16, 2025 - For example, let's take a string s = "geeks" and we need to perform a left and right shift of k=2 places: ... This article explores different ways to perform such shifts in Python using different methods, let's explore them with examples:
🌐
GeeksforGeeks
geeksforgeeks.org › python › turtle-right-method-in-python
turtle.right() method in Python - GeeksforGeeks
August 18, 2025 - Interview Questions · Examples ... Updated : 18 Aug, 2025 · turtle.right() method turns the turtle clockwise by the given angle (in degrees) without changing its position....
🌐
Vultr Docs
docs.vultr.com › python › standard-library › str › rjust
Python str rjust() - Right-Justify String | Vultr Docs
December 31, 2024 - This procedure aligns each column's headers and data entries to the right, ensuring all elements are vertically aligned and properly formatted. The str.rjust() method in Python simplifies the process of aligning text to the right, a common ...
🌐
Thedeveloperblog
thedeveloperblog.com › python › right-python
Python Right String Part
C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML ... Get the right part of strings by using a negative starting slice index.
🌐
ListenData
listendata.com › home › python
String Functions in Python with Examples
The table below shows many common string functions in Python along with their descriptions and their equivalent functions in MS Excel. If you are intermediate MS Excel users, you must have used LEFT, RIGHT and MID Functions.
🌐
Programiz
programiz.com › python-programming › methods › string › rjust
Python String rjust() (With Examples)
The rjust() method right aligns the string up to a given width using a specified character.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-substring-a-string-in-python
How to Substring a String in Python
January 3, 2020 - Notice that the start or end index can be a negative number. A negative index means that you start counting from the end of the string instead of the beginning (from the right to left).
🌐
Toppr
toppr.com › guides › python-guide › references › methods-and-functions › methods › string › rjust › python-string-rjust
Python rjust() function | Why do we use Python String rjust() function? |
September 27, 2021 - The Python rjust() string method returns a right-padded string of a given minimum width while using a specific character to fill the additional position of the string. The syntax followed by Python rjust() function is as below: ... width – ...
🌐
Reddit
reddit.com › r/learnpython › how do i align/move text right?
r/learnpython on Reddit: How do I align/move text right?
June 9, 2020 -

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

🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.right.html
pyspark.sql.functions.right — PySpark 4.1.2 documentation
Returns the rightmost len`(`len can be string type) characters from the string str, if len is less or equal than 0 the result is an empty string. New in version 3.5.0.
🌐
Delft Stack
delftstack.com › home › howto › python › right justify string in python
How to Right Justify String in Python | Delft Stack
February 20, 2025 - All the approaches discussed above are used to format variables with every data type. Python also provides us with methods specific to strings. We can use the rjust() method to right justify strings in python.