Python full stack development from getting started to giving up built-in functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.