With LIKE you search for the field (in my case, this field is real_name_test ) the values that you entered in the name
import pymysql name = input('Введите что то:\n') with pymysql.connect( host=host, port=3306, user=user, password=password, db="base", charset='utf8', autocommit=True) as cur: cur.execute("INSERT INTO Twiss (real_name_test) VALUES (%s)", (name,)) cur.execute("SELECT ID FROM Twiss WHERE real_name_test LIKE %s", (name,)) row = cur.fetchall() print('ID которое заполнилось = {}'.format(row[0][0]))
Conclusion
Введите что то: Данный для заполнения SQL ID которое заполнилось = 65