python基礎知識代碼執行個體實踐

來源:互聯網
上載者:User

標籤:

 1 --- 2 ** 3 2  3 ---True and True 4    True or False 5    not True 6  7 ---python is a smart language 8 5 / 2 == 5.0 / 2.0  //False 9 5 * 2 == 5.0 * 2.0 // True10 11 ---python is store values instead of expression12 13 ---str14 >>> 3 * ‘a‘15 ‘aaa‘16 17 >>> 3 * ‘ab‘18 ababab19 20 >>> ‘a‘ + ‘a‘21 aa22 23 >>> ‘a‘ + str(3)24 a325 26 function27      1. len()28      2. extract29          2.1 ‘abc‘[0]  >>> ‘a‘30              ‘abc‘[-1] >>> ‘c‘31          2.2 ‘string‘[beg:end]  [beg,end)32              ‘abc‘[1:3] >>> ‘bc‘ 33          2.3 ‘string‘[beg:end:step]34 35 ---raw_input()36 37 ---#38 39 ---40 x = int(raw_input(‘Enter an integer‘))41 if x%2 == 0:42     print(‘‘)43     print(‘Even‘)44 else:45     print(‘‘)46     print(‘Odd‘)47 print(‘Done with conditional‘)48 49 ---range(n) [0,n-1]50    range(n,m) [n,m-1]51 52 --- for letter in ‘hola‘:53     print letter  
顏色說明:  

這個是python和c++的不同

這個是python和matlab的不同

這個是困惑

這個是題目

1. print mystring 和 >>>mystring的區別

   >>>print mystring是調用str()

   >>>mystring 是調用repr()

2. _表示的是 上一個運算式的值。

運算式和語句的區別

運算式可以理解成  運算式;  在c++中是一個不合法語句

語句可以理解成  語句; 在c++中是一個合法的語句

3. % 輸出
>>>print ‘%s is number %d!‘ % (‘Python‘,1)Python is nubmer 1! 
4.輸入

 5.文檔字串

通過module.__doc__ 或者是class.__doc__ 或者是 function.__doc__調用 很像javadoc

6.優先順序

** >  + ->  + - * /

7. 3 < 4 < 5 := 3 < 4 and 4 < 58.操作符 無比的少

+ - * / %  ** 

沒有 -- 必須用 -= 1

筆試題:

1.  --2       //2 -(-2) ^_^

2.  2--       //error

9. 整形表示的範圍 >> c ++ 中的int10. 複數是1+2j不是1+2i11.List 可以修改,[ ] , 類型可以不同

12.Tuple 不可以修改,() , 類型可以不同

13. Dict

 

14.While

因為 while後面可以不用()  所以需要:說明條件寫完了

15. print內建換行 print a,內建空格16. 列表解析

 

17. 讀入檔案

18.函數 def

 

 

--------------------------------------------------------------------------------------------------

 

 

1.特殊字元

# 注釋

\n 換行

\ 繼續下一行   ‘‘‘ ‘‘‘ 或者() [] {} 不用顯示的寫出\

; 串連2句話

: 分開頭和體

2.單引號和三引號的區別

 

 

3.賦值賦的是引用,賦值不會返回傳回值

 4.變數賦值???

5.多元賦值 元組賦值

6.特殊變數

_xxx 不用‘from module import‘匯入

_xxx_ 系統定義名字

_xxx 類的私人變數名

7.布局???

 

注意:

1. import 後, 函數和類就被定義好.

2. 調用的函數是 __name__ = ‘__main__‘

    主函數是      __name__  = 模組名字

 

8.計數

增加 : 

1.對象建立

2.被引用

3.作為參數

4.成為一個容器的元素

 

減少:

1.離開{}

2.del y

3. remove(x)

4.del list

 

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.