0% found this document useful (0 votes)
3 views10 pages

Panduan Lengkap Array dan List Python

This document discusses arrays and lists in Python. It defines an array as a special variable that can hold more than one value. Lists are defined as ordered and changeable collections that allow duplicate members. The document provides code samples to demonstrate creating and manipulating arrays and lists through various methods like append, extend, remove, reverse, etc. It also discusses common list methods such as append, insert, pop, sort, and reverse.

Uploaded by

Fiona Tjia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Panduan Lengkap Array dan List Python

This document discusses arrays and lists in Python. It defines an array as a special variable that can hold more than one value. Lists are defined as ordered and changeable collections that allow duplicate members. The document provides code samples to demonstrate creating and manipulating arrays and lists through various methods like append, extend, remove, reverse, etc. It also discusses common list methods such as append, insert, pop, sort, and reverse.

Uploaded by

Fiona Tjia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algoritma dan

Pemrograman

Array
List

Adi
adi4vista@[Link]
Array
• What is array ?
– Special variable, which can hold more than one
value at a time.
• Module: array
Array
Array (sample)
import array

# create variable array, bertipe int, dan lakukan inisialisasi


arr = [Link]('i', [1, 2, 3, 4, 5, 6, 7, 8])

# liat isi variable array


for x in arr:
print(x, end=' ')
print()

# liat isi index pertama (0)


print(f"first item: {arr[0]}")

# list isi index terakhir


print(f"last item: {arr[len(arr)-1]}")
Array (sample)
# tambah elemen baru ke variable array
[Link](9)

# extend elemen baru ke variable array


[Link]([10, 11, 12])

print("after append and extend: ", end='')


for x in arr:
print(x, end=' ')
print()
Array (sample)
[Link](11)
[Link](12)

print("after remove 11 dan 12: ", end='')


for x in arr:
print(x, end=' ')
print()

arr2 = [Link]()

print("after reverse: ", end='')


for x in arr:
print(x, end=' ')
print()
List
• a collection which is ordered and changeable
• Allows duplicate members
• In Python lists are written with square
brackets
• Sample:
thislist = ["apple", "banana", "cherry"]
print(thislist)
List
• Cara membuat variable bertipe list
– var_list = []
– Var_list = list(iterable)
– Contoh
list = [] # list kosong
[Link](1)
[Link](“satu”)
[Link](False)
[Link](2.5)
List
• Method-method umum pada list:
• [Link](obj)
• [Link](iterable)
• [Link](i, obj)
• [Link](obj)
• [Link](i)
• [Link]()
• [Link](obj[,start[,end]])
• [Link](obj)
• [Link](key=None, reverse=False)
• [Link]()
• [Link]()

You might also like