'Can I write in a user input in Python? [duplicate]

I would like to add a "default value" to an input().

Something like this:

>>> x = input("Enter a number: ", value="0")
Enter a number: 0

So that the user can edit it, like the value attribute in html <input>

I tried using pyautogui:

import pyautogui

def input_value():
    x = input("Enter a number: ")
    pyautogui.hotkey("0")return x

But naturally it doesn't work because pyautogui.hotkey() is called after input().

Is there any way to do this?



Solution 1:[1]

Take a look at pyinputplus for enhanced input() functionality. If the online documentation isn't enough, you can also read Automate the Boring Stuff with Python for a good guide on using the module

https://pypi.org/project/PyInputPlus/

All input functions have the following parameters: default (str, None): A default value to use should the user time out or exceed the number of tries to enter valid input.

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 WAHISHON