[Python] The get() method on Python dicts and its "default" arg
2017-10-01 18:30
579 查看
# The get() method on dicts # and its "default" argument name_for_userid = { 382: "Alice", 590: "Bob", 951: "Dilbert", } def greeting(userid): return "Hi %s!" % name_for_userid.get(userid, "there") >>> greeting(382) "Hi Alice!" >>> greeting(333333) "Hi there!"
相关文章推荐
- Give a try to Python Flask and deploy it on VPS!
- Resolve and Remove "BAD PASSWORD: It is Based on a Dictionary Word "in Linux
- Resolve and Remove "BAD PASSWORD: It is Based on a Dictionary Word "in Linux
- discern the words in the picture and then search it on the web
- "AND" in linq? is it possible?
- Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the buil
- Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the buil
- Qtcreator远程调试出现“The selected build of GDB does not support Python scripting.It cannot be used .."
- 搭建 eclipse pydev python 开发环境 on mac and windows
- When Element add attribute by the method "setAttribute",It can't work in IE
- Bug on Build Solution: "Unable to copy file... because it is being used by another process.."
- The State of Visual Analytics Views on what visual analytics is and where it is going
- compass watch Encoding::CompatibilityError on line ["87"] encodings: GBK and UTF-8
- change from default to alternative Python version on Linux
- "Android SDK and AVD Manager" cannot be made visible because all of its children are in unavailable
- c# dynamic,maybe I should say it is just some shortcut for "Object", box and unbox, without the cast
- postgresql数据库无法连接,提示 Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP conn
- PatentTips - Method and system for browsing things of internet of things on ip using web platform
- What is the "internal" interface and port for on Openvswitch?
- [AS3.0] Error #1069: Property onBWDone not found on flash.net.NetConnection and there is no default value.解决办法