Last active
February 23, 2022 15:27
-
-
Save codistwa/bc02a35571e87fdb75ccd6738d4898e7 to your computer and use it in GitHub Desktop.
Course source code: https://codistwa.com/guides/data-structures-arrays. More courses on https://codistwa.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================ | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================ | |
// 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