Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "Some examples below for common list literals and operations."
  8. ]
  9. },
  10. {
  11. "cell_type": "code",
  12. "execution_count": 1,
  13. "metadata": {},
  14. "outputs": [
  15. {
  16. "ename": "TypeError",
  17. "evalue": "list indices must be integers or slices, not tuple",
  18. "output_type": "error",
  19. "traceback": [
  20. "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
  21. "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
  22. "\u001b[1;32m<ipython-input-1-b3b537c18651>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mmyList\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'Abhishek'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m25.08\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Jain'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'Administrator'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mmyList\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
  23. "\u001b[1;31mTypeError\u001b[0m: list indices must be integers or slices, not tuple"
  24. ]
  25. }
  26. ],
  27. "source": [
  28. "myList = ['Abhishek', 25.08,['Jain','Administrator']]\n",
  29. "\n",
  30. "myList[2,1]\n"
  31. ]
  32. },
  33. {
  34. "cell_type": "code",
  35. "execution_count": 2,
  36. "metadata": {},
  37. "outputs": [
  38. {
  39. "data": {
  40. "text/plain": [
  41. "'Administrator'"
  42. ]
  43. },
  44. "execution_count": 2,
  45. "metadata": {},
  46. "output_type": "execute_result"
  47. }
  48. ],
  49. "source": [
  50. "myList[2][1]"
  51. ]
  52. },
  53. {
  54. "cell_type": "code",
  55. "execution_count": 6,
  56. "metadata": {},
  57. "outputs": [
  58. {
  59. "data": {
  60. "text/plain": [
  61. "[25.08, ['Jain', 'Administrator']]"
  62. ]
  63. },
  64. "execution_count": 6,
  65. "metadata": {},
  66. "output_type": "execute_result"
  67. }
  68. ],
  69. "source": [
  70. "myList[1:3]"
  71. ]
  72. },
  73. {
  74. "cell_type": "code",
  75. "execution_count": 12,
  76. "metadata": {},
  77. "outputs": [],
  78. "source": [
  79. "myList.extend([5,6,7])"
  80. ]
  81. },
  82. {
  83. "cell_type": "code",
  84. "execution_count": 7,
  85. "metadata": {},
  86. "outputs": [
  87. {
  88. "data": {
  89. "text/plain": [
  90. "['Abhishek', 25.08, ['Jain', 'Administrator']]"
  91. ]
  92. },
  93. "execution_count": 7,
  94. "metadata": {},
  95. "output_type": "execute_result"
  96. }
  97. ],
  98. "source": [
  99. "myList"
  100. ]
  101. },
  102. {
  103. "cell_type": "code",
  104. "execution_count": 13,
  105. "metadata": {},
  106. "outputs": [
  107. {
  108. "name": "stdout",
  109. "output_type": "stream",
  110. "text": [
  111. "['Abhishek', 25.08, ['Jain', 'Administrator'], 'Jain', 'Jain', 5, 6, 7]\n"
  112. ]
  113. }
  114. ],
  115. "source": [
  116. "print(myList)"
  117. ]
  118. },
  119. {
  120. "cell_type": "code",
  121. "execution_count": 14,
  122. "metadata": {
  123. "collapsed": true
  124. },
  125. "outputs": [],
  126. "source": [
  127. "del myList[3:5]"
  128. ]
  129. },
  130. {
  131. "cell_type": "code",
  132. "execution_count": 15,
  133. "metadata": {},
  134. "outputs": [
  135. {
  136. "name": "stdout",
  137. "output_type": "stream",
  138. "text": [
  139. "['Abhishek', 25.08, ['Jain', 'Administrator'], 5, 6, 7]\n"
  140. ]
  141. }
  142. ],
  143. "source": [
  144. "print(myList)"
  145. ]
  146. },
  147. {
  148. "cell_type": "code",
  149. "execution_count": null,
  150. "metadata": {
  151. "collapsed": true
  152. },
  153. "outputs": [],
  154. "source": []
  155. }
  156. ],
  157. "metadata": {
  158. "kernelspec": {
  159. "display_name": "Python 3",
  160. "language": "python",
  161. "name": "python3"
  162. },
  163. "language_info": {
  164. "codemirror_mode": {
  165. "name": "ipython",
  166. "version": 3
  167. },
  168. "file_extension": ".py",
  169. "mimetype": "text/x-python",
  170. "name": "python",
  171. "nbconvert_exporter": "python",
  172. "pygments_lexer": "ipython3",
  173. "version": "3.6.1"
  174. }
  175. },
  176. "nbformat": 4,
  177. "nbformat_minor": 2
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement