python基本文法

來源:互聯網
上載者:User

標籤:python   put   不用   style   統一   參數   函數   span   區分   

1、代碼結構

  1)注釋

    單行注釋:# 

    多行注釋:""" """

      """

      a=11111

      print(a)

      """

  2)基礎資料型別 (Elementary Data Type)

   boolean: True 和False (python裡邊boolean類型的區分大小寫)

       int:    整數類型 (python不區分short,long,int 統一使用int來標識)

         str:字串(單引號,和雙引號來表示,python裡邊不做區分)

  3)變數賦值

    a=1111111;(變數賦值,定義變數都不用指定類型,類型根據函數type來判斷)example:print(type(a)) 輸出【class:int】

    x,y=1,2:多元賦值(表示 x=1,y=2)如果互動兩個的變數的值(y,x=1,2 或 x,y=2,1)

  4)對象比較

    ==比較值本身:example: x,y=1,1 print(x==y)

    id()比較是記憶體位址 example(print(id(x)=id(y)))

2、快速入門

  print(“name”)#輸出一個str

  print(“name”,“李四”)#輸出多個元素的值

  print(“age=”+23) #編譯出錯,因為str和int不能直接拼接到一起(注意)

  name=input(“請輸入姓名”);print(name)#input是接受控制台輸入的參數

3、for的產生式

  l1=[1,2,3,4,5]  

  l2=[ele+3 for ele in l1 if ele%2] # 被2整除的元素+3 產生新的集合

  

    

python基本文法

聯繫我們

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