Python學習-括弧,python學習括弧

來源:互聯網
上載者:User

Python學習-括弧,python學習括弧

python語言最常見的括弧有三種,分別是:小括弧( )、中括弧[ ]和大括弧也叫做花括弧{ }。其作用也各不相同,分別用來代表不同的python基本內建資料類型。

1、python中的小括弧( ):代表tuple元組資料類型,元組是一種不可變序列。建立方法很簡單,大多時候都是用小括弧括起來的。

1 #使用小括弧建立元組2 dims = (10,20,30,40)3 print(dims)4 5 #結果:6 #(10, 20, 30, 40)

2、python中的中括弧[ ]:代表list列表資料類型,列表是一種可變的序列。

1 #使用中括弧建立列表2 list = ['python','hello','world']3 print(list)4 5 #結果:6 #['python', 'hello', 'world']

3、python大括弧{ }花括弧:代表dict字典資料類型,字典是由鍵對值組組成。冒號':'分開鍵和值,逗號','隔開組。

1 #使用大括弧建立字典2 dic = {'jon':'boy','lili':'girl'}3 print(dic['lili'])4 5 #結果:6 #girl

 

聯繫我們

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