数组
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Python]]
&color(red){※This article is based on Python 3.7.3};
#contents
* 基本数组 [#q3a4b657]
定义
arr = []
增加元素
arr.append('aaa')
删除数组里的指定元素
del arr[0]
* 切片 [#z2d8dcce]
Python中的切片(slice)操作可以用来获取数组中的一部分数据...
#codeprettify{{
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
n = 5
print(a[:n])
}}
*列表解析 [#se5638b6]
列表解析(list comprehension)是一种简洁的方式来创建新的...
#codeprettify{{
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
n = 5
output = [x for x in a if x <= n]
print(output)
}}
* 遍历 [#x5e284b9]
#codeprettify{{
for x in [1,2,3]
print(x)
输出:
1
2
3
}}
#hr();
コメント:
#comment_kcaptcha
終了行:
[[Python]]
&color(red){※This article is based on Python 3.7.3};
#contents
* 基本数组 [#q3a4b657]
定义
arr = []
增加元素
arr.append('aaa')
删除数组里的指定元素
del arr[0]
* 切片 [#z2d8dcce]
Python中的切片(slice)操作可以用来获取数组中的一部分数据...
#codeprettify{{
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
n = 5
print(a[:n])
}}
*列表解析 [#se5638b6]
列表解析(list comprehension)是一种简洁的方式来创建新的...
#codeprettify{{
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
n = 5
output = [x for x in a if x <= n]
print(output)
}}
* 遍历 [#x5e284b9]
#codeprettify{{
for x in [1,2,3]
print(x)
输出:
1
2
3
}}
#hr();
コメント:
#comment_kcaptcha
ページ名: