'Change user input for python

i want to change user input, for example if a user puts in TT0101 i want my script to change it to TT7101 instead, i'm not able to find how to do this anywhere and am now wondering if it's even possible and if so where can i look into it?



Solution 1:[1]

It is not exactly clear what you want to achive, but I can try to answer your specific example. Just replace the char you want to change.

# user input
user_input = input("enter input:")

# user enters TT0101 so user_input equals "TT0101"

# replace first occurence of 0 with 7 
unser_input_changed = user_input.replace("0", "7", 1)

# prints TT7101
print(user_input_changed)

more info on the replace function

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 flexwend