*Array merupakan variabel tunggal yang dapat menampung banyak nilai tiap nilai ditampung dalam list /index.
2.Bagaimana cara mendeklarasikan sebuah array/larik di python
*array('c','Hello World')
array('u',u'hello \u 26441')
array('l',[1,2,3,4,5])
array('d',[1.0,2.0,3.14])
3.Bagaimana cara mengakses elemen sebuah array/larik di python
*a=[25,50]
print a[0] //Maka akan keluar 25 yang diambil dari A yang di atas
print b[1] //Maka akan keluar 50 yang diambil dari A yang di atas
untuk mengakses elemen array ini kita menggunakan indeks dimana indeks dimulai dari 0
4.Apa yang dimaksud dengan array/larik satu dimensi dua dimensi .bagaimana cara mendeklarasikan dan mengakses array/larik tsb,berikan contoh pemrograman
*Array satu dimensi
Merupakan sebuah variabel yang menyimpan sekumpulan data yang memiliki tipe sama dan elemen yang akan diakses hanya melalui 1 indeks atau subskrip.
Bentuk umum pendeklarasian:
nama_array[jumlah_eleman];
*Array dua dimensi
Merupakan sebuah variabel yang menyimpan sekumpulan data yang memiliki tipe sama dan elemen yang akan diakses melalui 2 indeks atau subskrip yaitu indeks baris dan indeks kolom.
Bentuk umum pendeklarasian:
nama_array[jumlah_eleman_baris][jumah_eleme_kolom];
5.Buatlah dan jelaskan langkah-langkah untuk membuat sebuah array/larik tiga dimensi berukuran 3x3x3 mengunakan python
array([[[1, 1, 1],
[1, 1, 1],
[0, 0, 0]],
[[2, 2, 2],
[2, 2, 2],
[2, 2, 2]],
[[3, 3, 3],
[3, 3, 3],
[1, 1, 1]]])
//tanda ( untuk awalan variabel //tanda [ yang awal ini di buat untuk awal array yang ke dua untuk array yang dimensi yang ketiga untuk bilangan itu sendiri
6.jelaskan beberapa istilah /methode/fungsi yang berkaitan dengan array/larik di python berikut
-subscript index,append,insert,remove,pop,count ,short,reverse,extend,def,filter,map,reduce
- list.append(x)
- Add an item to the end of the list; equivalent to a[len(a):] = [x].
- list.extend(L)
- Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.
- list.insert(i, x)
- Insert an item at a given position. The first argument is the index of the element before which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x).
- list.remove(x)
- Remove the first item from the list whose value is x. It is an error if there is no such item.
- list.pop([i])
- Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)
- list.index(x)
- Return the index in the list of the first item whose value is x. It is an error if there is no such item.
- list.count(x)
- Return the number of times x appears in the list.
- list.sort(cmp=None, key=None, reverse=False)
- Sort the items of the list in place (the arguments can be used for sort customization, see sorted() for their explanation).
- list.reverse()
- Reverse the elements of the list, in place.
>>> a = [66.25, 333, 333, 1, 1234.5]
>>> print a.count(333), a.count(66.25), a.count('x')
2 1 0
>>> a.insert(2, -1)
>>> a.append(333)
>>> a
[66.25, 333, -1, 333, 1, 1234.5, 333]
>>> a.index(333)
1
>>> a.remove(333)
>>> a
[66.25, -1, 333, 1, 1234.5, 333]
>>> a.reverse()
>>> a
[333, 1234.5, 1, 333, -1, 66.25]
>>> a.sort()
>>> a
[-1, 1, 66.25, 333, 333, 1234.5]
>>> a.pop()
1234.5
>>> a
[-1, 1, 66.25, 333, 333]
Tidak ada komentar:
Posting Komentar