1. 程式人生 > 實用技巧 >Day 1 Python入門

Day 1 Python入門

一 python是一門程式語言

程式語言 programming language

計算機程式語言是指用於人與計算機之間通訊的語言,是人與計算機之間傳遞資訊的,因為它是用來進行程式設計的,所以又稱程式設計語言或者程式語言。

A programming language is a formal language comprising a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms.

程式設計 programming

程式設計是編定程式的中文簡稱,就是讓計算機程式碼解決某個問題,對某個計算體系規定一定的運算方式,使計算體系按照該計算方式執行,並最終得到相應結果的過程。

Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task.

程式 program

計算機程式是一組計算機能識別和執行的指令,運行於電子計算機上,滿足人們某種需求的資訊化工具。

程序 process

程序(Process)是計算機中的程式關於某資料集合上的一次執行活動,是系統進行資源分配和排程的基本單位,是作業系統結構的基礎。在早期面向程序設計的計算機結構中,程序是程式的基本執行實體;在當代面向執行緒設計的計算機結構中,程序是執行緒的容器。程式是指令、資料及其組織形式的描述,程序是程式的實體。

為何要程式設計

為了讓計算機按照人類的思維邏輯(程式)自發地去工作從而把人力解放出來

The purpose of programming is to find a sequence of instructions that will automate the performance of a task (which can be as complex as an operating system) on a computer, often for solving a given problem.

二 計算機硬體

1.計算機的五大組成部分:

控制器 control unit

計算機的指揮系統

This is the core unit which manages the entire functioning of the computer device. It is one of the most essential components of the computer system.

The Control Unit collects the data entered using the input unit, leads it on for processing and once that is done, receives the output and presents it to the user. It can be said to the centre of all processing actions taking place inside a computer device.

Basically, the instructions taken, interpretation of entered data, issuing signals to execute the data and then finally retrieving the data is all done in the Control Unit.

運算器 arithmetic and logical unit

實現算術運算和邏輯運算的部件

As the name suggests, all the mathematical calculations or arithmetic operations are performed in the Arithmetic and Logical Unit of the CPU.

It can also perform actions like a comparison of data and decision-making actions. The ALU comprises circuits using which addition, subtraction, multiplication, division and other numerical based calculations can be performed.

控制器+運算器=CPU (Central Processing Unit)

相當於人類的大腦

儲存器 memory or storage unit

是計算機中用來存放所有資料和程式的記憶部件,它的基本功能是按指定的地址存入或者取出資訊。

記憶體 Internal storage

基於電工作,存放的是電訊號

特點:存取速度快,斷電消失

相當於人的短期記憶

外存 External storage

機械磁碟HDD

Hard disk drive:基於磁工作

特點:存取速度遠慢於記憶體,斷電資料不丟失,永久儲存資料

相當於人的記事筆記本

輸入裝置 input unit

輸入裝置是計算接收外界輸入資料的工具,如鍵盤、滑鼠,相當於人的眼睛或耳朵。

A computer will only respond when a command is given to the device. These commands can be given using the input unit or the input devices.

For example: Using a keyboard we can type things on a Notepad and the computer processes the entered data and then displays the output of the same of the screen.

The data entered can be in the form of numbers, alphabet, images, etc. We enter the information using an input device, the processing units convert it into computer understandable languages and then the final output is received by a human-understandable language.

輸出裝置 output unit

輸出裝置是計算機向外輸出資料的工具,如顯示器、印表機,相當於人說的話,寫出的文章。

When we command a computer to perform a task, it reverts back for the action performed and gives us a result. This result is called output. There are various output devices connected to the computer. The most basic of which is a monitor. Whatever we write using a keyboard or click using a mouse, is all displayed on the monitor.

Thus, the output unit gives us the final result once the entire processing is done within the mechanism of a device.

For example: when we visit an ATM, we enter our details like language, pin, amount to be withdrawn, etc. and then the final money which the cash dispenser releases is our outcome. In this case, the cash dispenser acts as an output unit.

儲存器如記憶體、磁碟等既是輸入裝置又是輸出裝置,統稱為IO裝置

When we enter the data into the computer using an input device, the entered information immediately gets saved in the memory unit of the Central Processing Unit (CPU). Because of the presence of some existing programming, the Memory Unit transmits the data further to the other parts of the CPU.

Similarly, when the output of our command is processed by the computer, it is saved in the memory unit before giving the output to the user.

2.軟體的執行與三大核心硬體的關係

三大核心硬體: 中央處理器, 記憶體,硬碟

中央處理器 CPU Central Processing Unit
CPU的分類
精簡指令集 RISC

Reduced instruction set computer

複雜指令集 CISC

Complex instruction set computer

CPU按照指令集可以分為精簡指令集CPU和複雜指令集CPU兩種,區別在於前者的指令集精簡,每個指令的執行時間都很短,完成的動作也很單純,指令的執行效能較佳;但是若要做複雜的事情,就要由多個指令來完成。後者的指令集每個小指令可以執行一些較低階的硬體操作,指令數目多而且複雜,每條指令的長度並不相同。因為指令執行較為複雜所以每條指令花費的時間較長,但每條個別指令可以處理的工作較為豐富
x86架構64位
x86-64是一個處理器的指令集架構,基於x86架構的64位拓展,向後兼容於16位及32位的x86架構。
4核 8執行緒CPU

多核心處理器 Multi-core processor

是在單個計算元件中加入兩個或以上的獨立實體中央處理單元(簡稱核心,英語:Core)。這些核心可以分別獨立地執行程式指令,利用平行計算的能力加快程式的執行速度。

多執行緒 Multithreading

指從軟體或者硬體上實現多個執行緒併發執行的技術。

記憶體 RAM Random Access Memory
buffer 緩衝

In computer science, a data buffer (or just buffer) is a region of a physical memory storage used to temporarily store data while it is being moved from one place to another.

緩衝器為暫時置放輸出或輸入資料的儲存器。

緩衝器內資料自儲存裝置(如硬碟),放置在緩衝器中,須待機送至CPU或其他運算裝置。

(linux不能隨便清)

cache 快取

In computing, a cache is a hardware or software component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere.

快取記憶體簡稱快取,原始意義是指訪問速度比一般隨機存取儲存器(RAM)快的一種RAM,通常它不像系統主存那樣使用DRAM技術,而使用昂貴但較快速的SRAM技術。

硬碟

磁軌

扇區 512位元組 硬碟最小儲存單位

柱面

機械硬碟HDD hard disk drive

IO延遲=平均尋道時間+平均延遲時間

一般小於20毫秒為可以接受

平均尋道時間 5毫秒

平均延遲時間 轉速(7200轉 大約4毫秒)

固態硬碟SSD Solid-state drive
虛擬記憶體 Virtual Memory

In computing, virtual memory is a memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine"which "creates the illusion to users of a very large memory".

虛擬記憶體是計算機系統記憶體管理的一種技術。它使得應用程式認為它擁有連續可用的記憶體(一個連續完整的地址空間),而實際上,它通常是被分隔成多個實體記憶體碎片,還有部分暫時儲存在外部磁碟儲存器上,在需要時進行資料交換。與沒有使用虛擬記憶體技術的系統相比,使用這種技術的系統使得大型程式的編寫變得更容易,對真正的實體記憶體(例如RAM)的使用也更有效率。

程式最先是存放於硬碟中的,程式的執行是先從硬碟把程式碼載入到記憶體中,然後cpu是從記憶體中讀取指令執行。

三 作業系統

計算機系統三層結構

應用程式

包括各類語言的直譯器以及圖形介面程式

(面向使用者)

作業系統

包含核心和系統介面層

(面向程式設計師)

計算機硬體

補充知識

1.馬雲與埃隆馬斯克對話

對話全文實錄:https://www.ifanr.com/1253696

2.《模仿遊戲》

二戰期間,英國劍橋大學的教授艾倫·圖靈(本尼迪克特·康伯巴奇 飾)獲軍情六處祕密任命,與一群專家組成解密組,試圖破解由納粹德國獨創,號稱世上最精密的情報機器——“Enigma”密碼機。圖靈獨具才能,被丘吉爾任命為組內的領導人,但其古怪的脾氣卻使他受到組員的抵制,過程遭遇重重挫折,幸好在聰明豔麗的新成員瓊恩·克拉克(凱拉·奈特莉 飾)的鼓勵下,圖靈主動打破和同僚的隔閡,最終合力研發出破譯地方機密的裝置,超過1400萬人得以避開戰火,而世上電腦的雛形亦宣告在那刻誕生。然而戰後多年,圖靈卻被揭發自己的同性戀傾向,而被英國政府入罪...

3.愛迪生和特斯拉

https://www.zhihu.com/question/20926563/answer/987769444?utm_source=wechat_timeline

4.量子計算機 Quantum computer

是一種使用量子邏輯進行通用計算的裝置。不同於電子計算機(或稱傳統計算機),量子計算用來儲存資料的物件是量子位元,它使用量子演算法來進行資料操作。馬約拉納費米子反粒子就是自己本身的屬性,或許是令量子計算機的製造變成現實的一個關鍵。量子計算機在輿論中有時被過度渲染成無所不能或速度快數億倍等,其實這種計算機是否強大極度看問題而定,若該問題已經有提出速算的量子演算法只是困於傳統計算機無法執行,那量子計算機確實能達到未有的高速,若是沒有發明演算法的問題則量子計算機表現與傳統無異甚至更差