python return

The return of the function must be written in a key place. Can't scribble
Do you understand the difference between the following two groups?
Can only return before the end of the task 
conn=MySQLdb.connect(**connection)
cur=conn.cursor()

cur.execute(sql)
results=cur.fetchall()
conn.cursor().close()
conn.commit()
conn.close()
return results





conn=MySQLdb.connect(**connection)
cur=conn.cursor()

cur.execute(sql)

results=cur.fetchall()
return results
conn.cursor().close()
conn.commit()
conn.close()

Guess you like

Origin blog.csdn.net/huochuangchuang/article/details/49429685