01 基礎知識

2022-09-08 08:51:10 字數 4993 閱讀 2258

1、計算機基礎:

cpu:相當於人的大腦,用於計算。

記憶體:儲存資料,4g,8g,16g,32g,成本高,斷電即消失。

硬碟:1t,固態硬碟,機械硬碟,儲存資料,應該長久保持資料,重要檔案,小電影等等。

2、編譯型語言和解釋型語言區別

編譯型:一次性將所有程式編譯成二進位制檔案。

缺點:開發效率低,不能跨平台。

優點:執行速度快。

例如:c,c++等等。

解釋型:當程式執行時,一行一行的解釋。

優點:開發效率高,可以跨平台。

缺點:執行速度慢。

例如:python ,php,等等。

3、python2和python3的區別

1、巨集觀區別:python2原始碼重複率高,不規範

2、python2預設編碼方式是ascii碼

python3預設編碼方式utf-8

當python2不能輸出中文時解決方式:在檔案的首行:插入-*- encoding:utf-8 -*-

例如:

-*- encoding:utf-8 -*-

print('我愛中國')

4、變數。

變數:就是將一些運算的中間結果暫存到記憶體中,以便後續**呼叫。

(1)必須由數字,字母,下劃線任意組合,且不能數字開頭。

(2)不能是python中的關鍵字。如下:

['and', 'as', 'assert', 'break', 'class', 'continue',

'def', 'del', 'elif', 'else', 'except', 'exec',

'finally', 'for', 'from', 'global', 'if', 'import',

'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',

'raise', 'return', 'try', 'while', 'with', 'yield']

(3)變數具有可描述性。

(4)不能是中文。

5、常量。

一直不變的量。 π

bir_of_china = 1949

6、注釋。

方便自己方便他人理解**。

單行注釋:#

多行注釋:'''被注釋內容''' """被注釋內容"""

7、使用者互動input。

(1)等待輸入

(2)將你輸入的內容賦值給了前面變數。

(3)input出來的資料型別全部是str

name = input('請輸入你的名字:')

請輸入你的名字:scm

age = input('請輸入你的年齡:')

請輸入你的年齡:26

print('我的名字是'+name,'我的年齡'+age+'歲')

我的名字是scm 我的年齡26歲

8、基礎資料型別初始。

數字:int 12,3,45

+ - * / **

% 取餘數

輸出資料型別:type()

字串轉化成數字:int(str) 條件:str必須是數字組成的。

數字轉化成字串:str(int)

字串:str,python當中凡是用引號引起來的都是字串。

可相加:字串的拼接。

可相乘:str * int

bool:布林值。 true false。

* 輸出資料格式

print(100,type(100))

100 print('100',type('100'))

100 *整型和字串之間的轉換

print(int('599'),type(int('599')))

599 print (str(123456),type(str(123456)))

123456 print (str123456,type(str(123456)))

*字串之間的拼接

a = '我'

b = '愛'

c = 'ni'

d = a+b+c

print(d)

我愛ni

*字串之間的乘積即複製

print(d*8)

我愛ni我愛ni我愛ni我愛ni我愛ni我愛ni我愛ni我愛ni

9、if。

if 條件:

結果

#第一種:

if 4 > 5 :

print('我請你喝酒')

print('喝什麼酒')

#第二種:

if 4 > 5:

print('我請你喝酒')

else:

print('喝什麼酒')

#多選:

(1)num = input('請輸入您猜的數字:')

if num == '1':

print('一起抽菸')

elif num == '2':

print('一起喝酒')

elif num == '3':

print('新開了一家,走看看')

else:

print('你猜錯了.....')

(2)score = int(input("輸入分數:"))

if score > 100:

print("我擦,最高分才100...")

elif score >= 90:

print("a")

elif score >= 60:

print("c")

elif score >= 80:

print("b")

elif score >= 40:

print("d")

else:

print("太笨了...e")

(3)name = input('請輸入名字:')

age = input('請輸入年齡:')

if name == '小二':

if age == '18':

print(666)

else:

print(333)

else:

print('錯了....')

10、while。

while 條件:

迴圈體無限迴圈。

終止迴圈:1,改變條件,使其不成立。

2,break、continue

二、break和continue的區別

1、break用於跳出乙個迴圈體或者完全結束乙個迴圈,不僅可以結束其所在的迴圈,還可結束其外層迴圈。

注意:(1)只能在迴圈體內和switch語句體內使用break。

(2)不管是哪種迴圈,一旦在迴圈體中遇到break,系統將完全結束迴圈,開始執行迴圈之後的**。

(3)當break出現在迴圈體中的switch語句體內時,起作用只是跳出該switch語句體,並不能終止迴圈體的執行。若想強行終止迴圈體的執行,可以在迴圈體中,但並不在switch語句中設定break語句,滿足某種條件則跳出本層迴圈體。

2、continue語句的作用是跳過本次迴圈體中剩下尚未執行的語句,立即進行下一次的迴圈條件判定,可以理解為只是中止(跳過)本次迴圈,接著開始下一次迴圈。

注意:(1)continue語句並沒有使整個迴圈終止。

(2)continue 只能在迴圈語句中使用,即只能在 for、while 和 do…while 語句中使用#while

print('111')

while true:

print('我們不一樣')

print('在人間')

print('癢')

print('222')

#輸出從1--100

(1)count = 1

flag = true

#標誌位

while flag:

print(count)

count = count + 1

if count > 100 :

flag = false

(2)count = 1

while count <= 100:

print(count)

count = count + 1

#求100以內自然數的和

count = 1

sum = 0

while count <= 100:

sum = sum + count

count = count + 1

print(sum)

#break:結束迴圈

(1)print('11')

while true:

print('222')

print(333)

break

print(444)

print('abc')

(2)count = 1

while true:

print(count)

count = count + 1

if count > 100:break

print(111)

continue:結束此次循壞

(1)count = 1

while count < 20 :

print(count)

continue

count = count + 1

(2)count = 0

while count <= 100 :

count += 1

if count > 5 and count < 95:

continue

print("loop ", count)

print("-----out of while loop ------")

01 基礎知識

程序概念 作業系統中所有執行中的任務通常是乙個程式,每個執行中的程式就是乙個程序 process 當乙個程式執行時,內部可能包含了多個順序執行流,每個順序執行流就是乙個執行緒。程序是處於執行過程中的程式,並且具有一定的獨立功能,程序是系統進行資源分配和排程的乙個獨立單位。程序三個特性 2.動態性 程...

彙編01 基礎知識

教材 80x86組合語言程式設計教程 楊季文 錢培德等編著 清華大學出版社 第一章 基礎知識 掌握的兩個要點 一是各進製的轉換,而是資料 非資料的表示和資料的型別 一 各進製的轉換 1 二進位制數和十六進製制數 在計算機裡,通常用數字後面跟乙個英文本母表示該數的數字 十進位制數一般用d,二進位制數用...

Python 基礎知識01

程式設計三個基礎元素 資料型別 基本資料型別 字串str 數字int float 布林bool 複數complex 組合資料型別 列表list 集合set 元組tuple 字典dict 引用資料型別 物件導向 資料型別轉換 數字 字串 str 字串 整數 int 字串 浮點數 float 布林 字串...