
27
2.3 基本的な橋渡し作業
表
2-2
リストと配列
JavaScript
配列(
a
)
Python
リスト(
l
)
a.length len(l)
a.push(item) l.append(item)
a.pop() l.pop()
a.shift() l.pop(0)
a.unshift(item) l.insert(0, item)
a.slice(start, end) l[start:end]
a.splice(start, howMany, i1,
…
) l[start:end] = [i1, ...]
2.3.14
関数
例
2-3
と例
2-4
のセクション
B
は、関数宣言を示しています。
Python
は
def
を使って関数を示
します。
def process_student_data(data, pass_threshold=60,
merit_threshold=75):
"""
学生データに基本的な統計処理を行う
"""
...
一方、
JavaScript
は
function
を使います。
function processStudentData(data, passThreshold, meritThreshold){
passThreshold = typeof passThreshold !== 'undefined'?
passThreshold: 60;
meritThreshold = typeof meritThreshold !== 'undefined'?
meritThreshold: 75; ...