Python代码阅读(第63篇):数字奇偶性

InfoQ 2021-11-25 16:11:30
代码 Python 阅读 数字 奇偶性

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Python 代码阅读合集介绍:","attrs":{}},{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s/7RqixavOlghqrTnr5GFeeA","title":"","type":null},"content":[{"type":"text","text":"为什么不推荐Python初学者直接看项目源码","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本篇阅读的代码实现了判断数字的奇偶性质,以及扩展判断一个数字能否被另一个数字整除的功能。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本篇阅读的代码片段来自于","attrs":{}},{"type":"link","attrs":{"href":"https://github.com/30-seconds/30-seconds-of-python","title":"","type":null},"content":[{"type":"text","text":"30-seconds-of-python","attrs":{}}]},{"type":"text","text":"。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"codeinline","content":[{"type":"text","text":"is_odd","attrs":{}}],"attrs":{}}]},{"type":"codeblock","attrs":{"lang":"python"},"content":[{"type":"text","text":"def is_odd(num):\n return num % 2 != 0\n\n# EXAMPLES\nis_odd(3) # True\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"is_odd","attrs":{}}],"attrs":{}},{"type":"text","text":"函数接收一个数字,返回这个数字是否是奇数。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"函数使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"%","attrs":{}}],"attrs":{}},{"type":"text","text":"运算符进行取余计算。奇数无法被","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"2","attrs":{}}],"attrs":{}},{"type":"text","text":"整除,所以使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"%","attrs":{}}],"attrs":{}},{"type":"text","text":"取余不等于","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"0","attrs":{}}],"attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"codeinline","content":[{"type":"text","text":"is_even","attrs":{}}],"attrs":{}}]},{"type":"codeblock","attrs":{"lang":"python"},"content":[{"type":"text","text":"def is_even(num):\n return num % 2 == 0\n\n# EXAMPLES\nis_even(3) # False\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"is_even","attrs":{}}],"attrs":{}},{"type":"text","text":"函数和","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"is_odd","attrs":{}}],"attrs":{}},{"type":"text","text":"函数类似,使用","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"%","attrs":{}}],"attrs":{}},{"type":"text","text":"判断是否可以被","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"2","attrs":{}}],"attrs":{}},{"type":"text","text":"整除。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"codeinline","content":[{"type":"text","text":"is_divisible","attrs":{}}],"attrs":{}}]},{"type":"codeblock","attrs":{"lang":"python"},"content":[{"type":"text","text":"def is_divisible(dividend, divisor):\n return dividend % divisor == 0\n\n# EXAMPLES\nis_divisible(6, 3) # True\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"is_divisible","attrs":{}}],"attrs":{}},{"type":"text","text":"函数扩展了前两个函数,使用指定的","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"divisor","attrs":{}}],"attrs":{}},{"type":"text","text":"进行取余计算。判断","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"dividend","attrs":{}}],"attrs":{}},{"type":"text","text":"能否被","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"divisor","attrs":{}}],"attrs":{}},{"type":"text","text":"整除。","attrs":{}}]}]}
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://xie.infoq.cn/article/24dd67581ab92b784706ede3a

  1. Using Python 3 to make practical software for drawing modification
  2. About HTML (acceptable to Python)
  3. Python集成學習:自己編寫構建AdaBoost分類模型可視化决策邊界及sklearn包調用比較
  4. PYTHON用LSTM長短期記憶神經網絡的參數優化方法預測時間序列洗發水銷售數據
  5. Python Integrated Learning: Writing and Constructing adaboost Classification Model Visualized decision Boundary and sklearn package Calling Comparison
  6. Python prédit les données de vente de shampooing de séries chronologiques en utilisant la méthode d'optimisation des paramètres du réseau neuronal de mémoire à court et à long terme lstm
  7. [zero basics of Python to introduction] a prerequisite for Python preparatory knowledge -- basic coding specification of Python
  8. OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)
  9. [zero basics of Python to getting started] a prerequisite for Python preparatory knowledge -- installing the visualization tool pycharm
  10. The test modifies main.py in micro python
  11. Microphoton experimental circuit board based on mm32f3273 - does not work normally
  12. Run micropathon on mm32f3273 to test performance
  13. Design mm32f3277 micro Python experimental board with SD card
  14. Mm32f3277 corresponding interface files during microphoton migration
  15. Mm32f3277 microphoton experimental board design and software testing
  16. Making and testing mm32f3277 microphoton minimum circuit board
  17. Download mm32-link program automatically with Python simulated mouse
  18. A curriculum of "artificial intelligence Python machine learning and deep learning"
  19. Test the basic functions of mm32 microphoton test circuit board
  20. Test the basic functions of the mm32f3277 micro Python development board flying one by one
  21. Debugging mm32f3277 from zhufei, transplanted with micro Python development board
  22. Recognizing numbers using OpenCV and python
  23. 真的太香了,Python速查表终于出中文版了
  24. Django REST Framework(DRF)教程:快速入门
  25. python django objects filter过滤查询:startswith year
  26. Data encapsulation of Excel test cases in Python
  27. 学员管理系统python
  28. 肝了一夜,8000字概括精髓,pandas必知必会50例!
  29. Python竟然可以画漫画!漫画版的故宫导游图,来袭!
  30. Networkx graph theory Dijkstra algorithm shortest path implementation, Python
  31. Draw a HelloWorld with Python turtle Library
  32. 运行django的服务器内存使用偶尔跳高一点,重启服务马上下来,是内存泄露吧
  33. Basic usage of Python tqdm module in machine learning training
  34. Python -- basic usage method and basic template of argparse module
  35. python-sockertserver并发编程思想
  36. Programmation simultanée du serveur de sockets Python
  37. Vue+Django 旅游网项目 首页前端实现
  38. [learning notes] Python - pyecarts
  39. Python automated operation and maintenance -- actual combat (I)
  40. Classic usage of pandas: iloc and LOC of data filtering
  41. Python 多分支语句的三种结构
  42. Calendar module of Python time series
  43. Python 输出指定范围的闰年
  44. A super easy to use Python standard library. It's great to operate directories and files
  45. Fatal Python error: init_ fs_ encoding: failed to get the Python codec of the filesystem encoding
  46. Using Python to obtain a video address is as simple as
  47. #yyds干货盘点# 6. Python 元组,不可变的列表,滚雪球学 Python
  48. Yyds Dry Inventory # 6. Python tuples, invariant List, snowball Learning Python
  49. You cannot enter the registration page using Django registration redux
  50. 笨办法学Python第十八天:更多文件操作
  51. Python编辑代码,帮个忙呗
  52. pandas转换object为int失败了,有人能解答吗
  53. python解释题,解释这串,所代表的意思
  54. 用python用while语句写1000以内能被5和9整除的数和个数
  55. #python 我写了一个“饭店”程序
  56. Comprehensive application of Python foundation -- Development
  57. Écrivez en python le nombre et le nombre d'entiers qui peuvent être divisés par 5 et 9 jusqu'à 1000 dans une instruction while
  58. You can learn Python articles without reading online classes (day 4)
  59. You can learn Python articles without reading online classes (the third day)
  60. You can learn Python articles without reading online classes (the next day)