Skip to content

Instantly share code, notes, and snippets.

@codistwa
Last active February 23, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codistwa/bc02a35571e87fdb75ccd6738d4898e7 to your computer and use it in GitHub Desktop.
Save codistwa/bc02a35571e87fdb75ccd6738d4898e7 to your computer and use it in GitHub Desktop.
# ============================================================
# Definition of an array
# ============================================================
empty = []
print(empty) # []
fruits = ['apple', 'lemon']
print(fruits) # [ 'apple', 'lemon' ]
# ============================================================
# Content of an array
# ============================================================
numbers = [1, 3, 5, 6]
print(numbers) # [ 1, 3, 5, 6 ]
fruits = ['apple', 'lemon']
print(fruits) # [ 'apple', 'lemon' ]
mix = [1, 'apple', 3, True, {'color': 'blue'}]
print(mix) # [ 1, 'apple', 3, true, { color: 'blue' } ]
# ============================================================
# Access to an item
# ============================================================
fruits = ['apple', 'lemon']
mix = [1, 'apple', 3, True, {'color': 'blue'}]
print(fruits[0]) # apple
print(mix[2]) # 3
# ============================================================
# Methods for an array
# ============================================================
numbers = [1, 3, 5, 6]
mix = [1, 'apple', 3, True, {'color': 'blue'}]
print(mix) # [1, 'apple', 3, True, {'color': 'blue'}]
print(numbers[2:]) # [5, 6]
numbers.append(1000)
print(numbers) # [1, 3, 5, 6, 1000]
print(len(numbers)) # 5
# ============================================================
# Multidimensional arrays
# ============================================================
multi_array = [[1, 2, 3, 4], [5, 6, 7]]
print(multi_array[0]) # [ 1, 2, 3, 4 ]
print(multi_array[0][2]) # 3
// ============================================================
// Definition of an array
// ============================================================
const empty = [];
console.log(empty); // []
const fruits = ['apple', 'lemon'];
console.log(fruits); // [ 'apple', 'lemon' ]
// ============================================================
// Content of an array
// ============================================================
const numbers = [1, 3, 5, 6];
console.log(numbers); // [ 1, 3, 5, 6 ]
const fruits = ['apple', 'lemon'];
console.log(fruits); // [ 'apple', 'lemon' ]
const mix = [1, 'apple', 3, true, {color: 'blue'}];
console.log(mix); // [ 1, 'apple', 3, true, { color: 'blue' } ]
// ============================================================
// Access to an item
// ============================================================
const fruits = ['apple', 'lemon'];
const mix = [1, 'apple', 3, true, {color: 'blue'}]
console.log(fruits[0]); // apple
console.log(mix[2]); // 3
// ============================================================
// Methods for an array
// ============================================================
const numbers = [1, 3, 5, 6];
const mix = [1, 'apple', 3, true, {color: 'blue'}]
console.log(mix); // [ 1, 'apple', 3, true, { color: 'blue' } ]
console.log(numbers.slice(2)); // [5, 6]
numbers.push(1000);
console.log(numbers); // [1, 3, 5, 6, 1000]
console.log(numbers.length); // 5
// ============================================================
// Multidimensional arrays
// ============================================================
const multiArray = [[1, 2, 3, 4], [5, 6, 7]];
console.log(multiArray[0]); // [ 1, 2, 3, 4 ]
console.log(multiArray[0][2]); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment