Q:

MySQLdb python 2.7

Main object is to pass variable in to statement but its not suiting with mysql syntax can I plz get some guidance of what I am doing wrong here? 
def sql_usercreation(endpoint, dbuser, dbpassword, username, password):

    db = MySQLdb.connect(endpoint, dbuser, dbpassword)

    cursor = db.cursor()
    cstmnt = cursor.execute("CREATE USER IF NOT EXIST %s@'%' IDENTIFIED BY %s",[username,password])
    dbguser = cursor.execute("select user,host from mysql.user")
    dboutput = cursor.fetchall()
    db.commit()
    db.close()
    print(dboutput)

sql_usercreation("hostendpointaddress", "dbadmin", "passworddbadmin", "username", "password")

error:
    query = query % args
ValueError: unsupported format character ''' (0x27) at index 30

A:

You have to escape your % character as %% 
cursor.execute("CREATE USER IF NOT EXIST %s@'%%' IDENTIFIED BY %s",[username,password])

