Python全棧開發,Day2

來源:互聯網
上載者:User

標籤:span   byte   建立項目   建立   國家   需求   continue   全棧   als   

一、Pycharm的使用

  1、建立項目

  2、python調整字型大小隨ctrl+滑鼠滾輪上下滾動

  3、python建立程式自動補全編碼和環境

  4、設定斷點(在代碼前面行號後面單擊滑鼠左鍵)

  5、調試斷點

 

二、in、not in
s = ‘老男孩alexwusir‘print(‘老男孩‘ in s)print(‘老男孩wusir‘ in s)print(‘老男‘ in s)print(‘老男‘ not in s)comment = input(‘請輸入你的評論:‘)if ‘蒼井空‘ in comment:    print(‘您輸入的禁用語,請重新輸入‘)

 在一個字串中,用一個母字串中包含的定義的子字串必須是連續的為True,不連續是False,in表示包含,not in表示非包含。

三、while else
count = 1while True:    print(count)    if count == 3:break    count += 1else:    print(‘迴圈正常完畢‘)
count = 1flag = Truewhile flag:    print(count)    if count == 3:        flag = False    count += 1else:    print(‘迴圈正常完畢‘)

如果迴圈被break打斷,程式不會走else

四、格式化輸出
% 預留位置 s str 字串 d digit 數字
第一種:
name = input(‘請輸入你的姓名:‘)age = input(‘請輸入你的年齡:‘)hobby = input(‘請輸入你的愛好:‘)msg = ‘我叫%s,今年%d歲,愛好%s‘ % (name,int(age),hobby)print(msg)
第二種
dic = {‘name‘:‘老男孩‘,‘age‘:51,‘hobby‘:‘無所謂‘}msg = ‘我叫%(name)s,今年%(age)d歲,愛好%(hobby)s‘ % dicprint(msg)
在格式化輸出中單純的顯示%  用%% 解決。
name = input(‘請輸入你的姓名:‘)age = input(‘請輸入你的年齡:‘)msg = ‘我叫%s,今年%d歲,學習進度為1%%‘ % (name,int(age))print(msg)
 五、運算子
and or not
第一種:前後都是比較運算。
優先順序:()> not > and > or 同一個優先順序,從左至右依次計算。
print(1 > 2 and 3 < 4 and 3 > 2 or 2 < 3)
print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)
第二種:前後都是數值運算。
x or y if x True,則 return x,否則 return y
print(1 or 3)
print(1 or 3)
print(2 or 3)
print(0 or 3)
print(-1 or 3)
print(1 and 2)
print(0 and 2)
第三種:混合。
print(1 > 2 or 3 and 4)
print(2 or 2 > 3 and 4)
print(0 or 2 > 3 and 4)
資料類型轉換:
int ---> bool  非0即True,0為False
bool---> int True 1 False 0
print(int(True))
print(int(False))
print(bool(100))
print(bool(0))
print(3 > 2 or 1 > 2)
如果or前面為非0數,只取前面的結果,and反之。
六、編碼

初期密碼本:
    asiic  包含數字,英文,特殊字元。八位
    01000001 01000010 01000011  A B C
    8位 = 1 byte  表示一個字元。

萬國碼unicode,將所有國家的語言套件含在這個密碼本。
    初期:16位,兩個位元組,表示一個字元。
          A : 00010000 00010010
          中: 00010010 00010010
    升級:32位,四個位元組,表示一個字元。
          A : 00010000 00010010 00010000 00010010
          中: 00010010 00010010 00010010 00010010
    資源浪費。

升級:utf-8。最少用8位(一個位元組),表示一個字元。
    英文:a :00010000 用8位表示一個字元。
    歐洲:00010000 00010000 16位兩個位元組表示一個字元。
    亞洲 中 :00010000 00010000 00010000 24位,三個位元組表示一個字元。

    utf-16

gbk:國標。
    只包含:英文中文。
        英文:a :00010000 8位,一個位元組表示一個字元。
        中文:中:00010000 00010000 16位,兩個位元組表示一個字元。
gb2312.....

知識回顧

判斷下列邏輯語句的True,False.

1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

2、求出下列邏輯語句的值。

1),8 or 3 and 4 or 2 and 0 or 9 and 7

2),0 or 2 and 3 and 4 or 6 and 0 or 3

3、下列結果是什嗎?

1)、6 or 2 > 1

2)、3 or 2 > 1

3)、0 or 5 < 4

4)、5 < 4 or 3

5)、2 > 1 or 6

6)、3 and 2 > 1

7)、0 and 3 > 1

8)、2 > 1 and 3

9)、3 > 1 and 0

10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2

4. 簡述變數命名規範

5. name = input(“>>>”) name變數是什麼資料類型?

6. if條件陳述式的基本結構?

7. while迴圈語句基本結構?

8. 寫代碼:計算 1 - 2 + 3 ... + 99 中除了88以外所有數的總和?

9. ?戶登陸(三次輸錯機會)且每次輸錯誤時顯示剩餘錯誤次數(提示:使?字串格式化)

10. 簡述ascii、unicode、utf-8編碼關係?

11. 簡述位和位元組的關係?

12. “?男孩”使?UTF-8編碼占??個位元組?使?GBK編碼占?個位元組?

13. 製作趣味模板程式需求:等待?戶輸?名字、地點、愛好,根據?戶的名字和愛好進?任意現實 如:敬愛可親的xxx,最喜歡在xxx地??xxx

14. 等待?戶輸?內容,檢測?戶輸?內容中是否包含敏感字元?如果存在敏感字元提示“存在敏感字元請重新輸?”,並允許?戶重新輸?並列印。敏感字元:“?粉嫩”、“?鐵鎚”

 

15. 單?注釋以及多?注釋?

 

16. 簡述你所知道的Python3和Python2的區別?

 

17. 看代碼書寫結果:

a = 1>2 or 4<7 and 8 == 8

print(a)

 

18.continue和break區別?

 

Day3默寫代碼:

Bit,Bytes,Kb,Mb,Gb,Tb之間的轉換關係。

Unicode,utf-8,gbk,每個編碼英文,中文,分別用幾個位元組表示。

 

True

False

 

 

 

7

3

 

 

 

6

3

0

3

True

True

0

3

0

4

 

 

 

不能特殊符號,_或字母開頭,簡潔且有含義,避開關鍵字

 

 

 

字串str

 

 

 

if 條件:

         結果

else:

         結果

 

 

 

while 條件:

         結果

 

 

 

count = 0
sum = 0
while count < 99:
    count += 1
    if count== 88:
        continue
    elif
count % 2 == 1:
        sum += count
    else:
        sum -= count
print(sum)

 

 

 

count = 3
while count > 0:
    username = input(輸入使用者名稱:‘)
    password = input(輸入密碼:‘)
    count -= 1
    if username== ‘hj‘ and password== ‘123‘:
        print(登入成功‘)
        break
    else
:
        pass
   
print(使用者名稱或密碼錯誤,剩餘輸入次數%s‘ % count)

 

 

 

 

 

 

 

name = input(請輸入名字:‘)
site = input(請輸入地點:‘)
hobby = input(請輸入愛好:‘)
msg = 敬愛可親的%s,最喜歡在%s地方幹%s‘ %(name,site,hobby)
print(msg)

 

 

 

flag = True
while
flag:
    keyword = 小粉嫩大鐵鎚‘
   
search = input(請輸入搜尋內容:‘)
    if searchin keyword:
        print(你輸入的內容含有敏感字,請重新輸入‘)
    else:
        print(成功輸入‘)
        flag = False

Python全棧開發,Day2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.