You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

2_Print_Statement.ipynb 11 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# Print 语句"
  8. ]
  9. },
  10. {
  11. "cell_type": "markdown",
  12. "metadata": {},
  13. "source": [
  14. "**print** 语句可以用下列不同的方式使用。\n",
  15. "\n",
  16. " - print(\"Hello World\")\n",
  17. " - print(\"Hello\", <Variable Containing the String>)\n",
  18. " - print(\"Hello\" + <Variable Containing the String>)\n",
  19. " - print(\"Hello %s\" % <variable containing the string>)"
  20. ]
  21. },
  22. {
  23. "cell_type": "code",
  24. "execution_count": 1,
  25. "metadata": {},
  26. "outputs": [
  27. {
  28. "name": "stdout",
  29. "output_type": "stream",
  30. "text": [
  31. "Hello World\n"
  32. ]
  33. }
  34. ],
  35. "source": [
  36. "print(\"Hello World\")"
  37. ]
  38. },
  39. {
  40. "cell_type": "markdown",
  41. "metadata": {},
  42. "source": [
  43. "在Python中,单引号、双引号和三引号用于表示字符串。\n",
  44. "大部分单引号用于声明一个字符。\n",
  45. "声明一行时使用双引号,声明段落/多行时使用三引号。"
  46. ]
  47. },
  48. {
  49. "cell_type": "code",
  50. "execution_count": 2,
  51. "metadata": {},
  52. "outputs": [
  53. {
  54. "name": "stdout",
  55. "output_type": "stream",
  56. "text": [
  57. "Hey\n"
  58. ]
  59. }
  60. ],
  61. "source": [
  62. "print('Hey')"
  63. ]
  64. },
  65. {
  66. "cell_type": "code",
  67. "execution_count": 6,
  68. "metadata": {},
  69. "outputs": [
  70. {
  71. "name": "stdout",
  72. "output_type": "stream",
  73. "text": [
  74. "My name is Rajath Kumar M.P.\n",
  75. "\n",
  76. "I love Python.\n"
  77. ]
  78. }
  79. ],
  80. "source": [
  81. "print(\"\"\"My name is Rajath Kumar M.P.\n",
  82. "\n",
  83. "I love Python.\"\"\")"
  84. ]
  85. },
  86. {
  87. "cell_type": "markdown",
  88. "metadata": {},
  89. "source": [
  90. "字符串可以分配给变量 _string1_ 和string2,使用print语句时可以调用。"
  91. ]
  92. },
  93. {
  94. "cell_type": "code",
  95. "execution_count": 1,
  96. "metadata": {
  97. "scrolled": true
  98. },
  99. "outputs": [
  100. {
  101. "name": "stdout",
  102. "output_type": "stream",
  103. "text": [
  104. "Hello World\n",
  105. "Hello World !\n"
  106. ]
  107. }
  108. ],
  109. "source": [
  110. "string1 = 'World'\n",
  111. "print('Hello', string1)\n",
  112. "\n",
  113. "string2 = '!'\n",
  114. "print('Hello', string1, string2)"
  115. ]
  116. },
  117. {
  118. "cell_type": "markdown",
  119. "metadata": {},
  120. "source": [
  121. "字符串连接是两个字符串的“加法”。注意,在连接时,字符串之间不会有空格。"
  122. ]
  123. },
  124. {
  125. "cell_type": "code",
  126. "execution_count": 8,
  127. "metadata": {},
  128. "outputs": [
  129. {
  130. "name": "stdout",
  131. "output_type": "stream",
  132. "text": [
  133. "HelloWorld!\n"
  134. ]
  135. }
  136. ],
  137. "source": [
  138. "print('Hello' + string1 + string2)"
  139. ]
  140. },
  141. {
  142. "cell_type": "markdown",
  143. "metadata": {},
  144. "source": [
  145. "**%s** 用于引用包含字符串的变量。"
  146. ]
  147. },
  148. {
  149. "cell_type": "code",
  150. "execution_count": 9,
  151. "metadata": {},
  152. "outputs": [
  153. {
  154. "name": "stdout",
  155. "output_type": "stream",
  156. "text": [
  157. "Hello World\n"
  158. ]
  159. }
  160. ],
  161. "source": [
  162. "print(\"Hello %s\" % string1)"
  163. ]
  164. },
  165. {
  166. "cell_type": "markdown",
  167. "metadata": {},
  168. "source": [
  169. "相似地,当我们使用其他的数据类型时\n",
  170. "\n",
  171. " - %s -> string\n",
  172. " - %d -> Integer\n",
  173. " - %f -> Float\n",
  174. " - %o -> Octal\n",
  175. " - %x -> Hexadecimal\n",
  176. " - %e -> exponential\n",
  177. " \n",
  178. "这可以用于print语句本身内部的转换。"
  179. ]
  180. },
  181. {
  182. "cell_type": "code",
  183. "execution_count": 10,
  184. "metadata": {},
  185. "outputs": [
  186. {
  187. "name": "stdout",
  188. "output_type": "stream",
  189. "text": [
  190. "Actual Number = 18\n",
  191. "Float of the number = 18.000000\n",
  192. "Octal equivalent of the number = 22\n",
  193. "Hexadecimal equivalent of the number = 12\n",
  194. "Exponential equivalent of the number = 1.800000e+01\n"
  195. ]
  196. }
  197. ],
  198. "source": [
  199. "print(\"Actual Number = %d\" % 18)\n",
  200. "print(\"Float of the number = %f\" % 18)\n",
  201. "print(\"Octal equivalent of the number = %o\" % 18)\n",
  202. "print(\"Hexadecimal equivalent of the number = %x\" % 18)\n",
  203. "print(\"Exponential equivalent of the number = %e\" % 18)"
  204. ]
  205. },
  206. {
  207. "cell_type": "markdown",
  208. "metadata": {},
  209. "source": [
  210. "当引用多个变量时使用圆括号。"
  211. ]
  212. },
  213. {
  214. "cell_type": "code",
  215. "execution_count": 11,
  216. "metadata": {},
  217. "outputs": [
  218. {
  219. "name": "stdout",
  220. "output_type": "stream",
  221. "text": [
  222. "Hello World !\n"
  223. ]
  224. }
  225. ],
  226. "source": [
  227. "print(\"Hello %s %s\" % (string1,string2))"
  228. ]
  229. },
  230. {
  231. "cell_type": "markdown",
  232. "metadata": {},
  233. "source": [
  234. "## 1. 其他例子"
  235. ]
  236. },
  237. {
  238. "cell_type": "markdown",
  239. "metadata": {},
  240. "source": [
  241. "下面是使用print语句的其他不同方式。"
  242. ]
  243. },
  244. {
  245. "cell_type": "code",
  246. "execution_count": 13,
  247. "metadata": {},
  248. "outputs": [
  249. {
  250. "name": "stdout",
  251. "output_type": "stream",
  252. "text": [
  253. "I want to be printed here\n"
  254. ]
  255. }
  256. ],
  257. "source": [
  258. "print(\"I want to be printed %s\" %'here')"
  259. ]
  260. },
  261. {
  262. "cell_type": "code",
  263. "execution_count": 14,
  264. "metadata": {},
  265. "outputs": [
  266. {
  267. "name": "stdout",
  268. "output_type": "stream",
  269. "text": [
  270. "_A_A_A_A_A_A_A_A_A_A\n"
  271. ]
  272. }
  273. ],
  274. "source": [
  275. "print('_A'*10)"
  276. ]
  277. },
  278. {
  279. "cell_type": "code",
  280. "execution_count": 15,
  281. "metadata": {},
  282. "outputs": [
  283. {
  284. "name": "stdout",
  285. "output_type": "stream",
  286. "text": [
  287. "Jan\n",
  288. "Feb\n",
  289. "Mar\n",
  290. "Apr\n",
  291. "May\n",
  292. "Jun\n",
  293. "Jul\n",
  294. "Aug\n"
  295. ]
  296. }
  297. ],
  298. "source": [
  299. "print(\"Jan\\nFeb\\nMar\\nApr\\nMay\\nJun\\nJul\\nAug\")"
  300. ]
  301. },
  302. {
  303. "cell_type": "code",
  304. "execution_count": 16,
  305. "metadata": {},
  306. "outputs": [
  307. {
  308. "name": "stdout",
  309. "output_type": "stream",
  310. "text": [
  311. "Jan\n",
  312. "Feb\n",
  313. "Mar\n",
  314. "Apr\n",
  315. "May\n",
  316. "Jun\n",
  317. "Jul\n",
  318. "Aug\n"
  319. ]
  320. }
  321. ],
  322. "source": [
  323. "print(\"\\n\".join(\"Jan Feb Mar Apr May Jun Jul Aug\".split(\" \")))"
  324. ]
  325. },
  326. {
  327. "cell_type": "code",
  328. "execution_count": 17,
  329. "metadata": {},
  330. "outputs": [
  331. {
  332. "name": "stdout",
  333. "output_type": "stream",
  334. "text": [
  335. "I want \\n to be printed.\n"
  336. ]
  337. }
  338. ],
  339. "source": [
  340. "print(\"I want \\\\n to be printed.\")"
  341. ]
  342. },
  343. {
  344. "cell_type": "code",
  345. "execution_count": 2,
  346. "metadata": {},
  347. "outputs": [
  348. {
  349. "name": "stdout",
  350. "output_type": "stream",
  351. "text": [
  352. "\n",
  353. "Routine:\n",
  354. "\t- Eat\n",
  355. "\t- Sleep\n",
  356. "\t- Repeat\n",
  357. "\n"
  358. ]
  359. }
  360. ],
  361. "source": [
  362. "print(\"\"\"\n",
  363. "Routine:\n",
  364. "\\t- Eat\n",
  365. "\\t- Sleep\\n\\t- Repeat\n",
  366. "\"\"\")"
  367. ]
  368. },
  369. {
  370. "cell_type": "markdown",
  371. "metadata": {},
  372. "source": [
  373. "# 2. PrecisionWidth和FieldWidth"
  374. ]
  375. },
  376. {
  377. "cell_type": "markdown",
  378. "metadata": {},
  379. "source": [
  380. "Fieldwidth是整个数字的宽度,精度是向右的宽度。你可以根据需要改变这些宽度。\n",
  381. "\n",
  382. "默认的精度宽度设置为6。"
  383. ]
  384. },
  385. {
  386. "cell_type": "code",
  387. "execution_count": 19,
  388. "metadata": {},
  389. "outputs": [
  390. {
  391. "data": {
  392. "text/plain": [
  393. "'3.121312'"
  394. ]
  395. },
  396. "execution_count": 19,
  397. "metadata": {},
  398. "output_type": "execute_result"
  399. }
  400. ],
  401. "source": [
  402. "\"%f\" % 3.121312312312"
  403. ]
  404. },
  405. {
  406. "cell_type": "markdown",
  407. "metadata": {},
  408. "source": [
  409. "注意,最多返回6个小数点。要指定小数点的数目,使用'%(fieldwidth).(precisionwidth)f'。"
  410. ]
  411. },
  412. {
  413. "cell_type": "code",
  414. "execution_count": 20,
  415. "metadata": {},
  416. "outputs": [
  417. {
  418. "data": {
  419. "text/plain": [
  420. "'3.12131'"
  421. ]
  422. },
  423. "execution_count": 20,
  424. "metadata": {},
  425. "output_type": "execute_result"
  426. }
  427. ],
  428. "source": [
  429. "\"%.5f\" % 3.121312312312"
  430. ]
  431. },
  432. {
  433. "cell_type": "markdown",
  434. "metadata": {},
  435. "source": [
  436. "如果字段宽度设置超过所需,则数据将自己对齐以调整到指定的值。"
  437. ]
  438. },
  439. {
  440. "cell_type": "code",
  441. "execution_count": 21,
  442. "metadata": {},
  443. "outputs": [
  444. {
  445. "data": {
  446. "text/plain": [
  447. "' 3.12131'"
  448. ]
  449. },
  450. "execution_count": 21,
  451. "metadata": {},
  452. "output_type": "execute_result"
  453. }
  454. ],
  455. "source": [
  456. "\"%9.5f\" % 3.121312312312"
  457. ]
  458. },
  459. {
  460. "cell_type": "markdown",
  461. "metadata": {},
  462. "source": [
  463. "零填充通过在字段宽度的开始处添加一个0来完成。"
  464. ]
  465. },
  466. {
  467. "cell_type": "code",
  468. "execution_count": 17,
  469. "metadata": {},
  470. "outputs": [
  471. {
  472. "data": {
  473. "text/plain": [
  474. "'00000000000003.12131'"
  475. ]
  476. },
  477. "execution_count": 17,
  478. "metadata": {},
  479. "output_type": "execute_result"
  480. }
  481. ],
  482. "source": [
  483. "\"%020.5f\" % 3.121312312312"
  484. ]
  485. },
  486. {
  487. "cell_type": "markdown",
  488. "metadata": {},
  489. "source": [
  490. "为了正确对齐,字段宽度中的空格可以留空,以便在使用负数时保持正确的对齐。"
  491. ]
  492. },
  493. {
  494. "cell_type": "code",
  495. "execution_count": 18,
  496. "metadata": {},
  497. "outputs": [
  498. {
  499. "name": "stdout",
  500. "output_type": "stream",
  501. "text": [
  502. " 3.121312\n",
  503. "-3.121312\n"
  504. ]
  505. }
  506. ],
  507. "source": [
  508. "print \"% 9f\" % 3.121312312312\n",
  509. "print \"% 9f\" % -3.121312312312"
  510. ]
  511. },
  512. {
  513. "cell_type": "markdown",
  514. "metadata": {},
  515. "source": [
  516. "通过在字段宽度的开始处添加一个+号,可以在正数的开始处返回'+'号。"
  517. ]
  518. },
  519. {
  520. "cell_type": "code",
  521. "execution_count": 19,
  522. "metadata": {},
  523. "outputs": [
  524. {
  525. "name": "stdout",
  526. "output_type": "stream",
  527. "text": [
  528. "+3.121312\n",
  529. "-3.121312\n"
  530. ]
  531. }
  532. ],
  533. "source": [
  534. "print \"%+9f\" % 3.121312312312\n",
  535. "print \"% 9f\" % -3.121312312312"
  536. ]
  537. },
  538. {
  539. "cell_type": "markdown",
  540. "metadata": {},
  541. "source": [
  542. "如上所述,当提到的字段宽度大于实际字段宽度时,数据右对齐。但是可以通过在字段宽度中指定一个负符号来实现左对齐。"
  543. ]
  544. },
  545. {
  546. "cell_type": "code",
  547. "execution_count": 16,
  548. "metadata": {},
  549. "outputs": [
  550. {
  551. "data": {
  552. "text/plain": [
  553. "'3.121 '"
  554. ]
  555. },
  556. "execution_count": 16,
  557. "metadata": {},
  558. "output_type": "execute_result"
  559. }
  560. ],
  561. "source": [
  562. "\"%-9.3f\" % 3.121312312312"
  563. ]
  564. }
  565. ],
  566. "metadata": {
  567. "kernelspec": {
  568. "display_name": "Python 3",
  569. "language": "python",
  570. "name": "python3"
  571. },
  572. "language_info": {
  573. "codemirror_mode": {
  574. "name": "ipython",
  575. "version": 3
  576. },
  577. "file_extension": ".py",
  578. "mimetype": "text/x-python",
  579. "name": "python",
  580. "nbconvert_exporter": "python",
  581. "pygments_lexer": "ipython3",
  582. "version": "3.6.8"
  583. }
  584. },
  585. "nbformat": 4,
  586. "nbformat_minor": 1
  587. }

机器学习越来越多应用到飞行器、机器人等领域,其目的是利用计算机实现类似人类的智能,从而实现装备的智能化与无人化。本课程旨在引导学生掌握机器学习的基本知识、典型方法与技术,通过具体的应用案例激发学生对该学科的兴趣,鼓励学生能够从人工智能的角度来分析、解决飞行器、机器人所面临的问题和挑战。本课程主要内容包括Python编程基础,机器学习模型,无监督学习、监督学习、深度学习基础知识与实现,并学习如何利用机器学习解决实际问题,从而全面提升自我的《综合能力》。