How to replace a zero with the number 1, but not in the middle of a number.

karilynae

Member
I'm using Text formatter: replace text to look for a zero and replace it with a 1. But I only want to replace it if the number is actually zero, not in the middle of a number like 205. Is there a way to do this?
 

ArshilAhmad

Well-known member
Staff member
Hi @karilynae,

Please try using this Python code to achieve your use case.
1723146456359.png


Python:
def replace_zero(num):
    # Check if the number is exactly 0
    if num == 0:
        return 1
    else:
        return num

# Test cases
print(replace_zero(205))

 
Top