简体   繁体   中英

Python Vscode Lambda issue

Vscode has an issue with the lambda expression when I create a function, it works until I either save the script or run the script then the code below get changed from this automatically

  a = lambda user : user + 10
  re = a(40)
  print(re)

to this

 def a(user): return user + 10
    re = a(40)
    print(re)

This is not a Vscode issue. It is due to pep8 auto formatting.(vscode is suggesting you the best way to write your code) Try to disable auto format in vscode. Go to File -> Preferences -> settings Look for python> Formatting autopep8 path and turn it to null or something. But I don't recommend to do that because according to pep8:

"Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifie"

edit: PEP8 Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM