Guest User

Untitled

a guest
Nov 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "Hi! John\n",
  13. "Hi! Nick\n"
  14. ]
  15. }
  16. ],
  17. "source": [
  18. "def greet(msg, name):\n",
  19. " print(msg + ' ' + name)\n",
  20. " \n",
  21. "def greet_hi(name):\n",
  22. " return greet('Hi!', name)\n",
  23. "\n",
  24. "greet_hi('John')\n",
  25. "greet_hi('Nick')"
  26. ]
  27. },
  28. {
  29. "cell_type": "code",
  30. "execution_count": 2,
  31. "metadata": {},
  32. "outputs": [
  33. {
  34. "name": "stdout",
  35. "output_type": "stream",
  36. "text": [
  37. "Hola! John\n",
  38. "Hola! Nick\n"
  39. ]
  40. }
  41. ],
  42. "source": [
  43. "from functools import partial\n",
  44. "greet_hola = partial(greet, msg='Hola!')\n",
  45. "\n",
  46. "greet_hola(name='John')\n",
  47. "greet_hola(name='Nick')"
  48. ]
  49. },
  50. {
  51. "cell_type": "code",
  52. "execution_count": 3,
  53. "metadata": {},
  54. "outputs": [
  55. {
  56. "name": "stdout",
  57. "output_type": "stream",
  58. "text": [
  59. "25\n",
  60. "125\n"
  61. ]
  62. }
  63. ],
  64. "source": [
  65. "def pow(base, exponent):\n",
  66. " print(base ** exponent)\n",
  67. "\n",
  68. "square = partial(pow, exponent=2)\n",
  69. "cube = partial(pow, exponent=3)\n",
  70. "\n",
  71. "square(5)\n",
  72. "cube(5)"
  73. ]
  74. }
  75. ],
  76. "metadata": {
  77. "kernelspec": {
  78. "display_name": "Python 3",
  79. "language": "python",
  80. "name": "python3"
  81. },
  82. "language_info": {
  83. "codemirror_mode": {
  84. "name": "ipython",
  85. "version": 3
  86. },
  87. "file_extension": ".py",
  88. "mimetype": "text/x-python",
  89. "name": "python",
  90. "nbconvert_exporter": "python",
  91. "pygments_lexer": "ipython3",
  92. "version": "3.5.2"
  93. }
  94. },
  95. "nbformat": 4,
  96. "nbformat_minor": 2
  97. }
Add Comment
Please, Sign In to add comment