1, locals, globals
1 def func (): 2 x = 13 y = 24print (Locals ()) # Prints the name in the local scope 5 Print# Prints the name in the global scope
2.
1 Print(123)2 "print (456)" #string3Eval"print (456)")#convert string to Python code to execute4 5 Output Results6123755W81exec("print (789)")91 num = 1+2+3Ten2 num = eval ("1+2+3")#execution will perform operation with return value One3Print(num) A4 -5 6 -1 num2 =exec("4+5+6")#executed, but no return value the2Print(num2) -3defmy_eval (): -4return1+2+3 -5 +6 -7 None
3, compile
1com = compile ("1+2+3","', mode='Eval')#save time, mode is specified with eval to invoke2 3 Print(eval (COM))4 Print(eval (COM))5 6 7 Print(Eval ("1+2+3"))
4, Pirnt
11Print('123', end="')#Eliminate line breaks22Print('456', end="')3 4 Print(a)#5 Print(1,2,3,4,5,6,sep=','), comma as delimiter6 Output Result:71 2 381,2,3,4,5,69 Ten Onef = open ('tmp','W')#open a file is not created A Print(1,2,3,file=f)#Print 123 to the file.
Python full stack development from getting started to giving up built-in functions