Advertisement
Guest User

Untitled

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