Shift Numbers in Python | Assignment Expert

Hello friends, in this article you will learn how to shift numbers in Python in a string from any place of string to the start of the string. For example, making bnj67jbn to 67bnjjbn, simply we need to remove integers from inside of a string and place them to start of the string. To check whether a character is a digit or not, we can use isdigit() method of Python.

Code to shift numbers in Python:

for i in range(len(mystr)):
    if mystr[i].isdigit():


Shift Numbers in Python | Assignment Expert


So, we created a string, declared two empty lists, then inside for loop, we checked each character of string whether it is digit or not. If its a digit, we will append it to list 1 else list 2. At last, we are printing both lists by converting them to strings(using join() method) and joining them with + operator.

Also Read:


Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you