函式
描述備註
max(item)
返回容器中元素最大值
如果是字典,只針對 key 比較
min(item)
返回容器中元素最小值
如果是字典,只針對 key 比較
cmp(item1, item2)
比較兩個值,-1 小於/0 相等/1 大於
python 3.x 取消了 cmp 函式
描述python 表示式
結果支援的資料型別
切片「0123456789」[::-2]
「97531」
字串、列表、元組
運算子python 表示式
結果描述
支援的資料型別
+[1, 2] + [3, 4]
[1, 2, 3, 4]
合併字串、列表、元組
*[「hi!」] * 4
[『hi!』, 『hi!』, 『hi!』, 『hi!』]
重複字串、列表、元組
in3 in (1, 2, 3)
true
元素是否存在
字串、列表、元組、字典
not in
4 not in (1, 2, 3)
true
元素是否不存在
字串、列表、元組、字典
> >= == < <=
(1, 2, 3) < (2, 2, 3)
true
元素比較
字串、列表、元組
注意
$ which python3
#! /usr/bin/python3
$ chmod +x cards_main.py
./cards_main.py
python學習筆記(三)
python的序列 列表,元組,字串都是列表,列表的主要特點是索引和切片操作 序列的基本操作 1.len 求序列的長度 2.連線兩個序列 3.重複序列元素 4.in判斷序列是否在元組中 5.max 返回最大值 6.min 返回最小值 7.cmp tup1,tup2 比較兩個序列的值 元組 元組和字串...
python學習筆記三
一 輸出 print的幾種用法 print hello world hello world中間有空格 print hello wolrd helloworld 中間沒有空格 print hello wolrd helloworld 中間沒有空格 print hello world hello wor...
python學習筆記(三)
list也可以直接做加法 a 1,2 a 3 a 1,2,3 lambda用來定義匿名函式 lambda x x 2.0 lambda x x 2.0 平方是用 student torture不理解 for可以各種巢狀 ppl alice bob carol doug excited ppl e f...