Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "## Functions in python"
  8. ]
  9. },
  10. {
  11. "cell_type": "code",
  12. "execution_count": 2,
  13. "metadata": {},
  14. "outputs": [
  15. {
  16. "name": "stdout",
  17. "output_type": "stream",
  18. "text": [
  19. "5\n"
  20. ]
  21. }
  22. ],
  23. "source": [
  24. "def add(a,b):\n",
  25. " return (a+b)\n",
  26. "c=add(2,3)\n",
  27. "print(c)"
  28. ]
  29. },
  30. {
  31. "cell_type": "code",
  32. "execution_count": 10,
  33. "metadata": {},
  34. "outputs": [
  35. {
  36. "name": "stdout",
  37. "output_type": "stream",
  38. "text": [
  39. "12\n",
  40. "omkaromkar\n"
  41. ]
  42. }
  43. ],
  44. "source": [
  45. "def mult(a,b):\n",
  46. " \n",
  47. " d=a*b\n",
  48. " return d\n",
  49. "print(mult(3,4))\n",
  50. "print(mult(2, \"omkar\"))\n"
  51. ]
  52. },
  53. {
  54. "cell_type": "code",
  55. "execution_count": 13,
  56. "metadata": {},
  57. "outputs": [
  58. {
  59. "name": "stdout",
  60. "output_type": "stream",
  61. "text": [
  62. "omkar kadam\n"
  63. ]
  64. }
  65. ],
  66. "source": [
  67. "def con (a,b):\n",
  68. " return(a + b)\n",
  69. "print(con(\"omkar \" ,\"kadam\"))"
  70. ]
  71. },
  72. {
  73. "cell_type": "code",
  74. "execution_count": 21,
  75. "metadata": {},
  76. "outputs": [
  77. {
  78. "name": "stdout",
  79. "output_type": "stream",
  80. "text": [
  81. "[0.2, 2, 3.4, 5, 6, 8, 9, 9.4, 10]\n",
  82. "[0.2, 2, 3.4, 5, 6, 8, 9, 9.4, 10]\n"
  83. ]
  84. }
  85. ],
  86. "source": [
  87. "album_rating=[10,2,3.4,5,8,6,9,0.2,9.4]\n",
  88. "sum(album_rating)\n",
  89. "len(album_rating)\n",
  90. "\n",
  91. "new=sorted(album_rating)\n",
  92. "print(new)\n",
  93. "\n",
  94. "album_rating.sort()\n",
  95. "print(album_rating)"
  96. ]
  97. },
  98. {
  99. "cell_type": "code",
  100. "execution_count": null,
  101. "metadata": {},
  102. "outputs": [],
  103. "source": [
  104. "#Global variable inside function scope\n",
  105. "var=\"GOT\"\n",
  106. "def fun(var):\n",
  107. " global new_var\n",
  108. " new_var = \" is shitty\"\n",
  109. " return(var+new_var)\n",
  110. "print(fun(var))\n",
  111. "print(new_var)"
  112. ]
  113. },
  114. {
  115. "cell_type": "code",
  116. "execution_count": null,
  117. "metadata": {},
  118. "outputs": [],
  119. "source": []
  120. }
  121. ],
  122. "metadata": {
  123. "kernelspec": {
  124. "display_name": "Python 3",
  125. "language": "python",
  126. "name": "python3"
  127. },
  128. "language_info": {
  129. "codemirror_mode": {
  130. "name": "ipython",
  131. "version": 3
  132. },
  133. "file_extension": ".py",
  134. "mimetype": "text/x-python",
  135. "name": "python",
  136. "nbconvert_exporter": "python",
  137. "pygments_lexer": "ipython3",
  138. "version": "3.6.8"
  139. }
  140. },
  141. "nbformat": 4,
  142. "nbformat_minor": 2
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement