Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "L = ['michael jacskon',10.2,1980]"
  10. ]
  11. },
  12. {
  13. "cell_type": "code",
  14. "execution_count": 2,
  15. "metadata": {},
  16. "outputs": [
  17. {
  18. "name": "stdout",
  19. "output_type": "stream",
  20. "text": [
  21. "michael jacskon\n"
  22. ]
  23. }
  24. ],
  25. "source": [
  26. "print(L[0])"
  27. ]
  28. },
  29. {
  30. "cell_type": "code",
  31. "execution_count": 4,
  32. "metadata": {},
  33. "outputs": [
  34. {
  35. "name": "stdout",
  36. "output_type": "stream",
  37. "text": [
  38. "1980\n"
  39. ]
  40. }
  41. ],
  42. "source": [
  43. "print(L[2])"
  44. ]
  45. },
  46. {
  47. "cell_type": "code",
  48. "execution_count": 5,
  49. "metadata": {},
  50. "outputs": [
  51. {
  52. "data": {
  53. "text/plain": [
  54. "10.2"
  55. ]
  56. },
  57. "execution_count": 5,
  58. "metadata": {},
  59. "output_type": "execute_result"
  60. }
  61. ],
  62. "source": [
  63. "L[1]"
  64. ]
  65. },
  66. {
  67. "cell_type": "code",
  68. "execution_count": 7,
  69. "metadata": {},
  70. "outputs": [],
  71. "source": [
  72. "A = ['michael Jackson',10.2,1980,[1,2],('a',1)]"
  73. ]
  74. },
  75. {
  76. "cell_type": "code",
  77. "execution_count": 8,
  78. "metadata": {},
  79. "outputs": [
  80. {
  81. "data": {
  82. "text/plain": [
  83. "1980"
  84. ]
  85. },
  86. "execution_count": 8,
  87. "metadata": {},
  88. "output_type": "execute_result"
  89. }
  90. ],
  91. "source": [
  92. "A[2]"
  93. ]
  94. },
  95. {
  96. "cell_type": "code",
  97. "execution_count": 10,
  98. "metadata": {},
  99. "outputs": [
  100. {
  101. "data": {
  102. "text/plain": [
  103. "[1, 2]"
  104. ]
  105. },
  106. "execution_count": 10,
  107. "metadata": {},
  108. "output_type": "execute_result"
  109. }
  110. ],
  111. "source": [
  112. "A[3]"
  113. ]
  114. },
  115. {
  116. "cell_type": "code",
  117. "execution_count": 11,
  118. "metadata": {},
  119. "outputs": [
  120. {
  121. "data": {
  122. "text/plain": [
  123. "('a', 1)"
  124. ]
  125. },
  126. "execution_count": 11,
  127. "metadata": {},
  128. "output_type": "execute_result"
  129. }
  130. ],
  131. "source": [
  132. "A[4]"
  133. ]
  134. },
  135. {
  136. "cell_type": "code",
  137. "execution_count": 17,
  138. "metadata": {},
  139. "outputs": [
  140. {
  141. "data": {
  142. "text/plain": [
  143. "['michael Jackson', 10.2, 1980, [1, 2]]"
  144. ]
  145. },
  146. "execution_count": 17,
  147. "metadata": {},
  148. "output_type": "execute_result"
  149. }
  150. ],
  151. "source": [
  152. "A[0:4]"
  153. ]
  154. },
  155. {
  156. "cell_type": "code",
  157. "execution_count": 22,
  158. "metadata": {},
  159. "outputs": [
  160. {
  161. "data": {
  162. "text/plain": [
  163. "['michael Jackson', ('a', 1)]"
  164. ]
  165. },
  166. "execution_count": 22,
  167. "metadata": {},
  168. "output_type": "execute_result"
  169. }
  170. ],
  171. "source": [
  172. "A[::4]"
  173. ]
  174. },
  175. {
  176. "cell_type": "code",
  177. "execution_count": 23,
  178. "metadata": {},
  179. "outputs": [
  180. {
  181. "data": {
  182. "text/plain": [
  183. "[[1, 2], ('a', 1)]"
  184. ]
  185. },
  186. "execution_count": 23,
  187. "metadata": {},
  188. "output_type": "execute_result"
  189. }
  190. ],
  191. "source": [
  192. "A[3:5]"
  193. ]
  194. },
  195. {
  196. "cell_type": "code",
  197. "execution_count": 14,
  198. "metadata": {},
  199. "outputs": [
  200. {
  201. "data": {
  202. "text/plain": [
  203. "['michael jacskon', 10.2, 1980, 'pop', 10]"
  204. ]
  205. },
  206. "execution_count": 14,
  207. "metadata": {},
  208. "output_type": "execute_result"
  209. }
  210. ],
  211. "source": [
  212. "L = ['michael jacskon',10.2,1980]\n",
  213. "L.extend(['pop',10])\n",
  214. "L\n"
  215. ]
  216. },
  217. {
  218. "cell_type": "code",
  219. "execution_count": 12,
  220. "metadata": {},
  221. "outputs": [],
  222. "source": [
  223. "L.extend(['pop',10])"
  224. ]
  225. },
  226. {
  227. "cell_type": "code",
  228. "execution_count": null,
  229. "metadata": {},
  230. "outputs": [],
  231. "source": []
  232. },
  233. {
  234. "cell_type": "code",
  235. "execution_count": 18,
  236. "metadata": {},
  237. "outputs": [
  238. {
  239. "data": {
  240. "text/plain": [
  241. "['michael jackson', 'dance', 12, ['pop', 'culture', 10]]"
  242. ]
  243. },
  244. "execution_count": 18,
  245. "metadata": {},
  246. "output_type": "execute_result"
  247. }
  248. ],
  249. "source": [
  250. "L=['michael jackson','dance',12]\n",
  251. "L.append(['pop','culture',10])\n",
  252. "L"
  253. ]
  254. },
  255. {
  256. "cell_type": "code",
  257. "execution_count": 20,
  258. "metadata": {},
  259. "outputs": [
  260. {
  261. "data": {
  262. "text/plain": [
  263. "['michael', 1, [1]]"
  264. ]
  265. },
  266. "execution_count": 20,
  267. "metadata": {},
  268. "output_type": "execute_result"
  269. }
  270. ],
  271. "source": [
  272. "L=['michael',1]\n",
  273. "L.append([1])\n",
  274. "L"
  275. ]
  276. },
  277. {
  278. "cell_type": "code",
  279. "execution_count": 24,
  280. "metadata": {},
  281. "outputs": [
  282. {
  283. "name": "stdout",
  284. "output_type": "stream",
  285. "text": [
  286. "Before change: ['disco', 10, 7]\n",
  287. "After change: ['rock', 10, 7]\n"
  288. ]
  289. }
  290. ],
  291. "source": [
  292. "A=['disco',10,7]\n",
  293. "print('Before change:',A)\n",
  294. "A[0]='rock'\n",
  295. "print('After change:',A)"
  296. ]
  297. },
  298. {
  299. "cell_type": "code",
  300. "execution_count": 25,
  301. "metadata": {},
  302. "outputs": [
  303. {
  304. "data": {
  305. "text/plain": [
  306. "['disco', 10, 'nice guy']"
  307. ]
  308. },
  309. "execution_count": 25,
  310. "metadata": {},
  311. "output_type": "execute_result"
  312. }
  313. ],
  314. "source": [
  315. "A=['disco',10,7]\n",
  316. "A[2]='nice guy'\n",
  317. "A"
  318. ]
  319. },
  320. {
  321. "cell_type": "code",
  322. "execution_count": 30,
  323. "metadata": {},
  324. "outputs": [
  325. {
  326. "data": {
  327. "text/plain": [
  328. "['disco', 7]"
  329. ]
  330. },
  331. "execution_count": 30,
  332. "metadata": {},
  333. "output_type": "execute_result"
  334. }
  335. ],
  336. "source": [
  337. "A=['disco',10,7]\n",
  338. "del(A[1])\n",
  339. "A"
  340. ]
  341. },
  342. {
  343. "cell_type": "code",
  344. "execution_count": 32,
  345. "metadata": {},
  346. "outputs": [
  347. {
  348. "data": {
  349. "text/plain": [
  350. "['hard', 'rock']"
  351. ]
  352. },
  353. "execution_count": 32,
  354. "metadata": {},
  355. "output_type": "execute_result"
  356. }
  357. ],
  358. "source": [
  359. "'hard rock'.split()"
  360. ]
  361. },
  362. {
  363. "cell_type": "code",
  364. "execution_count": 34,
  365. "metadata": {},
  366. "outputs": [
  367. {
  368. "data": {
  369. "text/plain": [
  370. "['h', 'ard']"
  371. ]
  372. },
  373. "execution_count": 34,
  374. "metadata": {},
  375. "output_type": "execute_result"
  376. }
  377. ],
  378. "source": [
  379. "'h ard'.split()"
  380. ]
  381. },
  382. {
  383. "cell_type": "code",
  384. "execution_count": 35,
  385. "metadata": {},
  386. "outputs": [
  387. {
  388. "data": {
  389. "text/plain": [
  390. "['A', 'B', 'C', 'D']"
  391. ]
  392. },
  393. "execution_count": 35,
  394. "metadata": {},
  395. "output_type": "execute_result"
  396. }
  397. ],
  398. "source": [
  399. "'A,B,C,D'.split(',')"
  400. ]
  401. },
  402. {
  403. "cell_type": "code",
  404. "execution_count": 36,
  405. "metadata": {},
  406. "outputs": [
  407. {
  408. "data": {
  409. "text/plain": [
  410. "['ABCD']"
  411. ]
  412. },
  413. "execution_count": 36,
  414. "metadata": {},
  415. "output_type": "execute_result"
  416. }
  417. ],
  418. "source": [
  419. "'ABCD'.split(',')"
  420. ]
  421. },
  422. {
  423. "cell_type": "code",
  424. "execution_count": 37,
  425. "metadata": {},
  426. "outputs": [
  427. {
  428. "ename": "ValueError",
  429. "evalue": "empty separator",
  430. "output_type": "error",
  431. "traceback": [
  432. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  433. "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
  434. "\u001b[0;32m<ipython-input-37-0843f17f434c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m\"ABCD\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
  435. "\u001b[0;31mValueError\u001b[0m: empty separator"
  436. ]
  437. }
  438. ],
  439. "source": [
  440. "\"ABCD\".split('')"
  441. ]
  442. },
  443. {
  444. "cell_type": "code",
  445. "execution_count": 38,
  446. "metadata": {},
  447. "outputs": [
  448. {
  449. "data": {
  450. "text/plain": [
  451. "['hard rock', 10, 1.2]"
  452. ]
  453. },
  454. "execution_count": 38,
  455. "metadata": {},
  456. "output_type": "execute_result"
  457. }
  458. ],
  459. "source": [
  460. "A=['hard rock',10,1.2]\n",
  461. "B=A\n",
  462. "B"
  463. ]
  464. },
  465. {
  466. "cell_type": "code",
  467. "execution_count": 43,
  468. "metadata": {},
  469. "outputs": [
  470. {
  471. "data": {
  472. "text/plain": [
  473. "['jeans', 10, 1.2]"
  474. ]
  475. },
  476. "execution_count": 43,
  477. "metadata": {},
  478. "output_type": "execute_result"
  479. }
  480. ],
  481. "source": [
  482. "B=A[:]\n",
  483. "B"
  484. ]
  485. },
  486. {
  487. "cell_type": "code",
  488. "execution_count": 39,
  489. "metadata": {},
  490. "outputs": [
  491. {
  492. "name": "stdout",
  493. "output_type": "stream",
  494. "text": [
  495. "['hard rock', 10, 1.2]\n",
  496. "['hard rock', 10, 1.2]\n"
  497. ]
  498. }
  499. ],
  500. "source": [
  501. "print(A)\n",
  502. "print(B)"
  503. ]
  504. },
  505. {
  506. "cell_type": "code",
  507. "execution_count": 41,
  508. "metadata": {},
  509. "outputs": [
  510. {
  511. "name": "stdout",
  512. "output_type": "stream",
  513. "text": [
  514. "jeans\n"
  515. ]
  516. }
  517. ],
  518. "source": [
  519. "A[0]='jeans'\n",
  520. "B[0]\n",
  521. "print(B[0])"
  522. ]
  523. },
  524. {
  525. "cell_type": "code",
  526. "execution_count": 42,
  527. "metadata": {},
  528. "outputs": [
  529. {
  530. "data": {
  531. "text/plain": [
  532. "['jeans', 10, 1.2]"
  533. ]
  534. },
  535. "execution_count": 42,
  536. "metadata": {},
  537. "output_type": "execute_result"
  538. }
  539. ],
  540. "source": [
  541. "B"
  542. ]
  543. },
  544. {
  545. "cell_type": "code",
  546. "execution_count": 44,
  547. "metadata": {},
  548. "outputs": [
  549. {
  550. "data": {
  551. "text/plain": [
  552. "['jeans', 10, 1.2]"
  553. ]
  554. },
  555. "execution_count": 44,
  556. "metadata": {},
  557. "output_type": "execute_result"
  558. }
  559. ],
  560. "source": [
  561. "B=A[:]\n",
  562. "B"
  563. ]
  564. },
  565. {
  566. "cell_type": "code",
  567. "execution_count": 45,
  568. "metadata": {},
  569. "outputs": [
  570. {
  571. "data": {
  572. "text/plain": [
  573. "['jeans', 10, 1.2]"
  574. ]
  575. },
  576. "execution_count": 45,
  577. "metadata": {},
  578. "output_type": "execute_result"
  579. }
  580. ],
  581. "source": [
  582. "A[0]='banana'\n",
  583. "B"
  584. ]
  585. },
  586. {
  587. "cell_type": "code",
  588. "execution_count": null,
  589. "metadata": {},
  590. "outputs": [],
  591. "source": [
  592. "A"
  593. ]
  594. }
  595. ],
  596. "metadata": {
  597. "kernelspec": {
  598. "display_name": "Python 3",
  599. "language": "python",
  600. "name": "python3"
  601. },
  602. "language_info": {
  603. "codemirror_mode": {
  604. "name": "ipython",
  605. "version": 3
  606. },
  607. "file_extension": ".py",
  608. "mimetype": "text/x-python",
  609. "name": "python",
  610. "nbconvert_exporter": "python",
  611. "pygments_lexer": "ipython3",
  612. "version": "3.6.7"
  613. }
  614. },
  615. "nbformat": 4,
  616. "nbformat_minor": 4
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement