1. 程式人生 > >python 學習 D1

python 學習 D1

種類 回車 -- tro pre 區別 font yield odin

1. 初識計算機。CPU 內存,硬盤,操作系統

CPU:大腦,中央處理器,運算計算中心。
內存:臨時存儲數據,供cpu運算。
優點:讀取速度快。
缺點:容量小,成本高,斷電即消失。
硬盤:長時間存儲數據,大量的數據。500G,1T,2T,大片,小視頻。
優點:容量大,成本低,斷電不消失。、
缺點:讀取速度慢。
操作系統:調配,各個硬件的運行。
windows,linux,cenos,mac,。。。

2. python初識

python發展史以影響。
python:優美,清晰,簡單。
1大區別:
python2x: 源碼不規範,源碼混亂,重復代碼較多。
python3x: 重整源碼,源碼規範,優美,清晰,簡單。


4,Python的分類。

編譯型:
將代碼一次性全部編譯成二級制,然後在運行。
優點:執行效率高。
缺點:開發效率慢,不能跨平臺。
代表語言:C。
解釋型:
代碼逐行解釋,解釋稱二進制,然後運行。
優點:開發效率高,第三方庫,可以跨平臺。
缺點:執行效率低。
代表語言:python.

5,Python的種類。

5.5 運行第一個python文件:
python 空格 文件路徑,回車。
python2x: 默認的編碼方式ascii,
顯示中文:首行:# -*- encoding: utf-8 -*-。
python3x: 默認的編碼方式utf-8,。
python2x: print ‘內容‘ print(‘內容‘)


python3x: print(‘內容‘)。

6,變量。
#變量:將計算的中間結果存儲起來,以便後續代碼使用。
變量設定規則:
1,必須是字母,數字下劃線任意組合。
2,不能是數字開頭。
3,不能是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‘]
4,變量不能是中文。
5,變量不能太長。
6,變量有具有可描述性。
AgeOfOldboy = 56
NumberOfStudents = 80
#下劃線
age_of_oldboy = 56
number_of_students = 80
#常量:一直不變的量。默認全部大寫的變量為常量。
# 身份證號,π,
#註釋。
# 幫助你理解別人代碼,回憶自己的代碼。
#單行註釋:# 多行註釋 ‘‘‘ 被註釋內容‘‘‘ """ 被註釋內容"""

#基礎數據類型:

int 數字,整數。用於計算。+ - * / % //
str ;字符串。在python中,凡是用引號引起來的就是字符串。
#print(‘這是字符串‘)
#print("這是字符串")

#msg = ‘‘‘
床前明月光,
疑是地上霜。
‘‘‘
字符串:可加,可乘。

print(這是字符串)
# print("這是字符串")
# 
# msg = ‘‘‘
# 床前明月光,
# 疑是地上霜。
# ‘‘‘
# print(msg)

str + str :字符串的拼接。、

# msg1 = ‘老男孩教育‘
# msg2 = ‘   是最好的培訓機構‘
# #print(msg1+msg2)
#  msg = 堅強
#print(msg * 8)

相乘:
str * int
msg = ‘堅強‘
#print(msg * 8)

#bool True False 兩種狀態:判定代碼的真假。

#print(3 > 2)
#print(3 > 4)

#print(‘True‘)
#print(True)
# 判斷此對象是什麽數據類型 type()

# print(‘中國你好‘)

# print(1+2+3+6+7+8+101)
# print((1+2+3+6+7+8+101)*3/5)
# print(((1+2+3+6+7+8+101)*3/5)*4/8)
#
# a = 1+2+3+6+7+8+101
# b = a*3/5
# c = b*4/8
# print(c)


#print(‘True‘,type(‘True‘))
#print(True,type(True))

# #變量:將計算的中間結果存儲起來,以便後續代碼使用。
# a_ = 4
# a*c = 3
# ___ = 22
# _+ = 23
# _ _ = 15
# 12e = 66
#
# age1 = 12
# AGE2 = age1
# age3 = age2
# age2 = 23
# print(age1,age2,age3) # 12 23 12  12 12 12

10,input用戶輸入。

name = input(請輸入你的名字:)
age = input(請輸入你的年齡:)
print(name,age,type(name),type(age))

11,if。
其他語言:
if (條件){結果}
if 條件:
結果

#單獨if
‘‘‘
print(111)
if 3 > 2:
    print(666)
print(333)
‘‘‘
#if else
‘‘‘
name = input(‘請輸入你的名字:‘)
if name == ‘王爺‘:
    print(‘老鐵,沒毛病‘)
else:
    print(‘有病得治....‘)

#if elif ... num = int(input(‘請輸入你得選擇:‘)) # str ---> int str全部由數字組成 if num == 4: print(‘中午飯我請‘) elif num == 5: print(‘晚飯我請‘) elif num == 6: print(‘大保健,走起‘)
‘‘‘
#if elif ... else
‘‘‘
num = int(input(‘請輸入你得選擇:‘))  # str ---> int str全部由數字組成
if num == 4:
    print(‘中午飯我請‘)
elif num == 5:
    print(‘晚飯我請‘)
elif num == 6:
    print(‘大保健,走起‘)
else:
    print(‘給你機會抓不住....‘)
‘‘‘
# 嵌套
‘‘‘
num1 = input(‘請輸入數字‘)
if num1 == ‘3‘:
    num2 = input(‘請輸入數字:‘)
    if num2 == ‘5‘:
        print(‘這都能猜對‘)
    else:
        print(‘繼續努力‘)
score = int(input("輸入分數:"))
if score > 100:
    print("我擦,最高分才100...")
elif score >= 80:
    print("B")
elif score >= 90:
    print("A")
elif score >= 60:
    print("C")
elif score >= 40:
    print("D")
else:
    print("太笨了...E")
‘‘‘

12,while。
#while
終止循環:

‘‘‘
while 條件:
    結果


while True:
    print(‘精忠報國‘)
    print(‘粉紅的回憶‘)
    print(‘涼涼‘)
    print(‘起風了‘)


flag = True
while flag:
    print(‘精忠報國‘)
    print(‘粉紅的回憶‘)
    print(‘涼涼‘)
    flag = False

flag = True
while flag:
    print(‘精忠報國‘)
    print(‘粉紅的回憶‘)
    print(‘涼涼‘)
    flag = False
    print(‘第一次‘)


count = 1
flag = True
while flag:
    print(count)
    count = count + 1 # count += 1
    if count == 101:
        flag = False

count = 1
while count < 101:
    print(count)
    count = count + 1 # count += 1

count = 0
while count < 101:
    print(count)
    count = count + 2 
    
count = 0
while count < 101:
    if count % 2 == 0:
        print(count)
    count = count + 1

while True:
    print(111)
    print(222)
    break
    print(333)
print(666)

while True:
    print(111)
    print(222)
    continue
    print(333)
print(666)
‘‘‘


1,改變條件。
2,break.(直接結束循環。)
關鍵字:break,
continue,結束本次循環,繼續下一次循環。

PS

#break while 循環 計算出1+2+3+4...+100
# count = 1
# sum = 0
# while True:
#     sum = sum + count
#     count = count + 1
#     if count == 101:break
#     
# print(sum)

python 學習 D1