【Python】 條件判斷 與 迴圈 與dict和set

來源:互聯網
上載者:User

標籤:

# 條件判斷

elif:  else if 的作用

注意: : 【冒號】
BMI =w/(h*h)

if BMI<15:
    print(‘較輕‘)
elif BMI<25:
    print(‘正常‘)
else BIM:
    print(‘肥胖‘)

# 迴圈

for x in xs  有點類似 C#的foreach
range()  產生整數序列,range(101) 產生0~100的整數序列

while 迴圈

 

找不同
一、

n = 11while n>10:    n-1    print(n)

二、

n = 20while n > 10:    n = n-1    print(‘1‘,n)

一和二的不同,,,

 #dict和set

dict 字典 dictionary 簡寫,

key-value儲存,

速度快,索引,

與list相比優點

  1. 尋找和插入的速度極快,不會隨著key的增加而增加;
  2. 需要佔用大量的記憶體,記憶體浪費多。

缺點:

  1. 尋找和插入的時間隨著元素的增加而增加;
  2. 佔用空間小,浪費記憶體很少。

set與dict同是不可變對對象

不可變對象-->只是把值改變了,對象本身並沒有改變。

用在哪裡呢???

【Python】 條件判斷 與 迴圈 與dict和set

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.