├── memulai_python ├── instalasi_python.txt └── pengenalan_python.py ├── python_dasar ├── hello_world.py ├── print.py ├── contoh_modul.py ├── string_sederhana.py ├── update_variabel_string.py ├── contoh_fungsi.py ├── kalender_python.py ├── mendapatkan_waktu_sekarang.py ├── hapus_nilai_tuple.py ├── import_modul.py ├── mendapatkan_waktu_berformat.py ├── tanggal_waktu_python.py ├── nilai_dalam_string.py ├── while_loop.py ├── update_list_python.py ├── list_python_sederhana.py ├── membuat_tuple_python.py ├── akses_nilai_tuple_python.py ├── hapus_nilai_pada_list.py ├── membuat_dictionary_python.py ├── input_python.py ├── mengakses_nilai_dalam_list.py ├── for_loop.py ├── nested_loop.py ├── update_dictionary_python.py ├── update_nilai_tuple_python.py ├── triple_quote_python.py ├── menghapus_dictionary_python.py ├── kondisi-if-else.py ├── komentar.py ├── kondisi-if.py ├── kondisi-elif.py ├── variabel.py ├── tipe_date.py └── operator_aritmatika.py ├── python_tingkat_lanjut ├── membuat_class.py ├── koneksi_database.py ├── delete_operation.py ├── create_table_database.py ├── update_operation.py ├── operasi_insert.py ├── insert_operation.py ├── insert_operation2.py ├── instance_object.py └── read_operation.py └── README.md /memulai_python/instalasi_python.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /python_dasar/hello_world.py: -------------------------------------------------------------------------------- 1 | print("Hello World") 2 | -------------------------------------------------------------------------------- /memulai_python/pengenalan_python.py: -------------------------------------------------------------------------------- 1 | print("Python sangat simpel") 2 | 3 | -------------------------------------------------------------------------------- /python_dasar/print.py: -------------------------------------------------------------------------------- 1 | print ("Python adalah bahasa pemrograman yang hebat") 2 | -------------------------------------------------------------------------------- /python_dasar/contoh_modul.py: -------------------------------------------------------------------------------- 1 | def print_func( par ): 2 | print "Halo : ", par 3 | return 4 | -------------------------------------------------------------------------------- /python_dasar/string_sederhana.py: -------------------------------------------------------------------------------- 1 | var = 'Hello World!' message = "Selamat datang di Belajarpython" 2 | -------------------------------------------------------------------------------- /python_dasar/update_variabel_string.py: -------------------------------------------------------------------------------- 1 | message = 'Hello World' 2 | print ("Updated String :- ", message[:6] + 'Python') 3 | -------------------------------------------------------------------------------- /python_dasar/contoh_fungsi.py: -------------------------------------------------------------------------------- 1 | def printme( str ): 2 | "This prints a passed string into this function" 3 | print (str) 4 | return 5 | -------------------------------------------------------------------------------- /python_dasar/kalender_python.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | 3 | cal = calendar.month(2008, 1) 4 | print "Dibawah ini adalah kalender:" 5 | print cal 6 | -------------------------------------------------------------------------------- /python_dasar/mendapatkan_waktu_sekarang.py: -------------------------------------------------------------------------------- 1 | import time; 2 | 3 | localtime = time.localtime(time.time()) 4 | print "Waktu lokal saat ini :", localtime 5 | -------------------------------------------------------------------------------- /python_dasar/hapus_nilai_tuple.py: -------------------------------------------------------------------------------- 1 | tup = ('fisika', 'kimia', 1993, 2017); 2 | 3 | print (tup) 4 | del tup; 5 | print "Setelah menghapus tuple : " 6 | print tup 7 | -------------------------------------------------------------------------------- /python_dasar/import_modul.py: -------------------------------------------------------------------------------- 1 | # Import module support 2 | import support 3 | 4 | # Anda bisa memanggil fungsi defined sebagai berikut 5 | support.print_func("Andy") 6 | -------------------------------------------------------------------------------- /python_dasar/mendapatkan_waktu_berformat.py: -------------------------------------------------------------------------------- 1 | import time; 2 | 3 | localtime = time.asctime( time.localtime(time.time()) ) 4 | print "Waktu lokal saat ini :", localtime 5 | -------------------------------------------------------------------------------- /python_dasar/tanggal_waktu_python.py: -------------------------------------------------------------------------------- 1 | import time; # Digunakan untuk meng-import modul time 2 | 3 | ticks = time.time() 4 | print "Berjalan sejak 12:00am, January 1, 1970:", ticks 5 | -------------------------------------------------------------------------------- /python_dasar/nilai_dalam_string.py: -------------------------------------------------------------------------------- 1 | name = 'John Doe' message = "John Doe belajar bahasa python di Belajarpython" 2 | print ("name[0]: ", name[0]) 3 | print ("message[1:4]: ", message[1:4]) 4 | -------------------------------------------------------------------------------- /python_dasar/while_loop.py: -------------------------------------------------------------------------------- 1 | #Contoh penggunaan While Loop 2 | 3 | count = 0 4 | while (count < 9): 5 | print ('The count is:', count) 6 | count = count + 1 7 | 8 | print ("Good bye!") 9 | -------------------------------------------------------------------------------- /python_dasar/update_list_python.py: -------------------------------------------------------------------------------- 1 | list = ['fisika', 'kimia', 1993, 2017] 2 | print ("Nilai ada pada index 2 : ", list[2]) 3 | 4 | list[2] = 2001 5 | print ("Nilai baru ada pada index 2 : ", list[2]) 6 | -------------------------------------------------------------------------------- /python_dasar/list_python_sederhana.py: -------------------------------------------------------------------------------- 1 | #Contoh sederhana pembuatan list pada bahasa pemrograman python 2 | list1 = ['kimia', 'fisika', 1993, 2017] 3 | list2 = [1, 2, 3, 4, 5 ] 4 | list3 = ["a", "b", "c", "d"] 5 | -------------------------------------------------------------------------------- /python_dasar/membuat_tuple_python.py: -------------------------------------------------------------------------------- 1 | #Contoh sederhana pembuatan tuple pada bahasa pemrograman python 2 | 3 | tup1 = ('fisika', 'kimia', 1993, 2017) 4 | tup2 = (1, 2, 3, 4, 5 ) 5 | tup3 = "a", "b", "c", "d" 6 | -------------------------------------------------------------------------------- /python_dasar/akses_nilai_tuple_python.py: -------------------------------------------------------------------------------- 1 | #Cara mengakses nilai tuple 2 | 3 | tup1 = ('fisika', 'kimia', 1993, 2017) 4 | tup2 = (1, 2, 3, 4, 5, 6, 7 ) 5 | 6 | print ("tup1[0]: ", tup1[0]) 7 | print ("tup2[1:5]: ", tup2[1:5]) 8 | -------------------------------------------------------------------------------- /python_dasar/hapus_nilai_pada_list.py: -------------------------------------------------------------------------------- 1 | #Contoh cara menghapus nilai pada list python 2 | 3 | list = ['fisika', 'kimia', 1993, 2017] 4 | 5 | print (list) 6 | del list[2] 7 | print ("Setelah dihapus nilai pada index 2 : ", list) 8 | -------------------------------------------------------------------------------- /python_dasar/membuat_dictionary_python.py: -------------------------------------------------------------------------------- 1 | #Contoh cara membuat Dictionary pada Python 2 | 3 | dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} 4 | print ("dict['Name']: ", dict['Name']) 5 | print ("dict['Age']: ", dict['Age']) 6 | -------------------------------------------------------------------------------- /python_dasar/input_python.py: -------------------------------------------------------------------------------- 1 | >>> x = input("something:") 2 | something:10 3 | 4 | >>> x 5 | '10' 6 | 7 | >>> x = input("something:") 8 | something:'10' #entered data treated as string with or without '' 9 | 10 | >>> x 11 | "'10'" 12 | -------------------------------------------------------------------------------- /python_dasar/mengakses_nilai_dalam_list.py: -------------------------------------------------------------------------------- 1 | #Cara mengakses nilai di dalam list Python 2 | 3 | list1 = ['fisika', 'kimia', 1993, 2017] 4 | list2 = [1, 2, 3, 4, 5, 6, 7 ] 5 | 6 | print ("list1[0]: ", list1[0]) 7 | print ("list2[1:5]: ", list2[1:5]) 8 | -------------------------------------------------------------------------------- /python_dasar/for_loop.py: -------------------------------------------------------------------------------- 1 | #Contoh pengulangan for sederhana 2 | angka = [1,2,3,4,5] 3 | for x in angka: 4 | print(x) 5 | 6 | #Contoh pengulangan for 7 | buah = ["nanas", "apel", "jeruk"] 8 | for makanan in buah: 9 | print("Saya suka makan", makanan) 10 | -------------------------------------------------------------------------------- /python_dasar/nested_loop.py: -------------------------------------------------------------------------------- 1 | #Contoh penggunaan Nested Loop 2 | 3 | i = 2 4 | while(i < 100): 5 | j = 2 6 | while(j <= (i/j)): 7 | if not(i%j): break 8 | j = j + 1 9 | if (j > i/j) : print(i, " is prime") 10 | i = i + 1 11 | 12 | print "Good bye!" 13 | -------------------------------------------------------------------------------- /python_dasar/update_dictionary_python.py: -------------------------------------------------------------------------------- 1 | #Update dictionary python 2 | 3 | dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} 4 | dict['Age'] = 8; # Mengubah entri yang sudah ada 5 | dict['School'] = "DPS School" # Menambah entri baru 6 | 7 | print ("dict['Age']: ", dict['Age']) 8 | print ("dict['School']: ", dict['School']) 9 | -------------------------------------------------------------------------------- /python_dasar/update_nilai_tuple_python.py: -------------------------------------------------------------------------------- 1 | tup1 = (12, 34.56) 2 | tup2 = ('abc', 'xyz') 3 | 4 | # Aksi seperti dibawah ini tidak bisa dilakukan pada tuple python 5 | # Karena memang nilai pada tuple python tidak bisa diubah 6 | # tup1[0] = 100; 7 | 8 | # Jadi, buatlah tuple baru sebagai berikut 9 | tup3 = tup1 + tup2 10 | print (tup3) 11 | -------------------------------------------------------------------------------- /python_dasar/triple_quote_python.py: -------------------------------------------------------------------------------- 1 | kutipantiga = """this is a long string that is made up of 2 | several lines and non-printable characters such as 3 | TAB ( \t ) and they will show up that way when displayed. 4 | NEWLINEs within the string, whether explicitly given like 5 | this within the brackets [ \n ], or just a NEWLINE within 6 | the variable assignment will also show up. 7 | """ 8 | print (kutipantiga) 9 | -------------------------------------------------------------------------------- /python_dasar/menghapus_dictionary_python.py: -------------------------------------------------------------------------------- 1 | #Contoh cara menghapus pada Dictionary Python 2 | 3 | dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} 4 | 5 | del dict['Name'] # hapus entri dengan key 'Name' 6 | dict.clear() # hapus semua entri di dict 7 | del dict # hapus dictionary yang sudah ada 8 | 9 | print ("dict['Age']: ", dict['Age']) 10 | print ("dict['School']: ", dict['School']) 11 | -------------------------------------------------------------------------------- /python_dasar/kondisi-if-else.py: -------------------------------------------------------------------------------- 1 | #Kondisi if else adalah jika kondisi bernilai TRUE maka akan dieksekusi pada if, tetapi jika bernilai FALSE maka akan dieksekusi kode pada else 2 | 3 | nilai = 3 4 | #Jika pernyataan pada if bernilai TRUE maka if akan dieksekusi, tetapi jika FALSE kode pada else yang akan dieksekusi. 5 | if(nilai > 7): 6 | print("Selamat Anda Lulus") 7 | else: 8 | print("Maaf Anda Tidak Lulus") 9 | -------------------------------------------------------------------------------- /python_dasar/komentar.py: -------------------------------------------------------------------------------- 1 | #Ini adalah komentar 2 | # Tulisan ini tidak akan dieksekusi 3 | 4 | #komentar dengan tanda pagar hanya bisa digunakan 5 | #untuk 6 | #satu 7 | #baris 8 | 9 | print("Hello World") #ini juga komentar 10 | 11 | #print("Welcome") 12 | 13 | # komentar bisa berisi spesial karakter !@#$%^&*(),./;'[]\ 14 | 15 | #mencetak nama 16 | print("Budi") 17 | 18 | #mencetak angka/integer 19 | print(123) 20 | -------------------------------------------------------------------------------- /python_dasar/kondisi-if.py: -------------------------------------------------------------------------------- 1 | #Kondisi if adalah kondisi yang akan dieksekusi oleh program jika bernilai benar atau TRUE 2 | 3 | nilai = 9 4 | 5 | #jika kondisi benar/TRUE maka program akan mengeksekusi perintah dibawahnya 6 | if(nilai > 7): 7 | print("Selamat Anda Lulus") 8 | 9 | #jika kondisi salah/FALSE maka program tidak akan mengeksekusi perintah dibawahnya 10 | if(nilai > 10): 11 | print("Selamat Anda Lulus") 12 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/membuat_class.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | 'Common base class for all employees' 3 | empCount = 0 4 | 5 | def __init__(self, name, salary): 6 | self.name = name 7 | self.salary = salary 8 | Employee.empCount += 1 9 | 10 | def displayCount(self): 11 | print "Total Employee %d" % Employee.empCount 12 | 13 | def displayEmployee(self): 14 | print "Name : ", self.name, ", Salary: ", self.salary 15 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/koneksi_database.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # execute SQL query using execute() method. 10 | cursor.execute("SELECT VERSION()") 11 | 12 | # Fetch a single row using fetchone() method. 13 | data = cursor.fetchone() 14 | 15 | print ("Database version : %s " % data) 16 | 17 | # disconnect from server 18 | db.close() 19 | -------------------------------------------------------------------------------- /python_dasar/kondisi-elif.py: -------------------------------------------------------------------------------- 1 | #Contoh penggunaan kondisi elif 2 | 3 | hari_ini = "Minggu" 4 | 5 | if(hari_ini == "Senin"): 6 | print("Saya akan kuliah") 7 | elif(hari_ini == "Selasa"): 8 | print("Saya akan kuliah") 9 | elif(hari_ini == "Rabu"): 10 | print("Saya akan kuliah") 11 | elif(hari_ini == "Kamis"): 12 | print("Saya akan kuliah") 13 | elif(hari_ini == "Jumat"): 14 | print("Saya akan kuliah") 15 | elif(hari_ini == "Sabtu"): 16 | print("Saya akan kuliah") 17 | elif(hari_ini == "Minggu"): 18 | print("Saya akan libur") 19 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/delete_operation.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Prepare SQL query to DELETE required records 10 | sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20) 11 | try: 12 | # Execute the SQL command 13 | cursor.execute(sql) 14 | # Commit your changes in the database 15 | db.commit() 16 | except: 17 | # Rollback in case there is any error 18 | db.rollback() 19 | 20 | # disconnect from server 21 | db.close() 22 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/create_table_database.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Drop table if it already exist using execute() method. 10 | cursor.execute("DROP TABLE IF EXISTS EMPLOYEE") 11 | 12 | # Create table as per requirement 13 | sql = """CREATE TABLE EMPLOYEE ( 14 | FIRST_NAME CHAR(20) NOT NULL, 15 | LAST_NAME CHAR(20), 16 | AGE INT, 17 | SEX CHAR(1), 18 | INCOME FLOAT )""" 19 | 20 | cursor.execute(sql) 21 | 22 | # disconnect from server 23 | db.close() 24 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/update_operation.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Prepare SQL query to UPDATE required records 10 | sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 11 | WHERE SEX = '%c'" % ('M') 12 | try: 13 | # Execute the SQL command 14 | cursor.execute(sql) 15 | # Commit your changes in the database 16 | db.commit() 17 | except: 18 | # Rollback in case there is any error 19 | db.rollback() 20 | 21 | # disconnect from server 22 | db.close() 23 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/operasi_insert.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Prepare SQL query to INSERT a record into the database. 10 | sql = """INSERT INTO EMPLOYEE(FIRST_NAME, 11 | LAST_NAME, AGE, SEX, INCOME) 12 | VALUES ('Mac', 'Mohan', 20, 'M', 2000)""" 13 | try: 14 | # Execute the SQL command 15 | cursor.execute(sql) 16 | # Commit your changes in the database 17 | db.commit() 18 | except: 19 | # Rollback in case there is any error 20 | db.rollback() 21 | 22 | # disconnect from server 23 | db.close() 24 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/insert_operation.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Prepare SQL query to INSERT a record into the database. 10 | sql = """INSERT INTO EMPLOYEE(FIRST_NAME, 11 | LAST_NAME, AGE, SEX, INCOME) 12 | VALUES ('Mac', 'Mohan', 20, 'M', 2000)""" 13 | try: 14 | # Execute the SQL command 15 | cursor.execute(sql) 16 | # Commit your changes in the database 17 | db.commit() 18 | except: 19 | # Rollback in case there is any error 20 | db.rollback() 21 | 22 | # disconnect from server 23 | db.close() 24 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/insert_operation2.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Prepare SQL query to INSERT a record into the database. 10 | sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \ 11 | LAST_NAME, AGE, SEX, INCOME) \ 12 | VALUES ('%s', '%s', '%d', '%c', '%d' )" % \ 13 | ('Mac', 'Mohan', 20, 'M', 2000) 14 | try: 15 | # Execute the SQL command 16 | cursor.execute(sql) 17 | # Commit your changes in the database 18 | db.commit() 19 | except: 20 | # Rollback in case there is any error 21 | db.rollback() 22 | 23 | # disconnect from server 24 | db.close() 25 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/instance_object.py: -------------------------------------------------------------------------------- 1 | class Employee: 2 | 'Common base class for all employees' 3 | empCount = 0 4 | 5 | def __init__(self, name, salary): 6 | self.name = name 7 | self.salary = salary 8 | Employee.empCount += 1 9 | 10 | def displayCount(self): 11 | print ("Total Employee %d" % Employee.empCount) 12 | 13 | def displayEmployee(self): 14 | print ("Name : ", self.name, ", Salary: ", self.salary) 15 | 16 | 17 | #This would create first object of Employee class" 18 | emp1 = Employee("Zara", 2000) 19 | #This would create second object of Employee class" 20 | emp2 = Employee("Manni", 5000) 21 | emp1.displayEmployee() 22 | emp2.displayEmployee() 23 | print ("Total Employee %d" % Employee.empCount) 24 | -------------------------------------------------------------------------------- /python_dasar/variabel.py: -------------------------------------------------------------------------------- 1 | #proses memasukan data ke dalam variabel 2 | nama = "John Doe" 3 | #proses mencetak variabel 4 | print(nama) 5 | 6 | #nilai dan tipe data dalam variabel dapat diubah 7 | umur = 20 #nilai awal 8 | print(umur) #mencetak nilai umur 9 | type(umur) #mengecek tipe data umur 10 | umur = "dua puluh satu" #nilai setelah diubah 11 | print(umur) #mencetak nilai umur 12 | type(umur) #mengecek tipe data umur 13 | 14 | namaDepan = "Budi" 15 | namaBelakang = "Susanto" 16 | nama = namaDepan + " " + namaBelakang 17 | umur = 22 18 | hobi = "Berenang" 19 | print("Biodata\n", nama, "\n", umur, "\n", hobi) 20 | 21 | #contoh variabel lainya 22 | inivariabel = "Halo" 23 | ini_juga_variabel = "Hai" 24 | _inivariabeljuga = "Hi" 25 | inivariabel222 = "Bye" 26 | 27 | panjang = 10 28 | lebar = 5 29 | luas = panjang * lebar 30 | print(luas) 31 | -------------------------------------------------------------------------------- /python_dasar/tipe_date.py: -------------------------------------------------------------------------------- 1 | #tipe data Boolean 2 | print(True) 3 | 4 | #tipe data String 5 | print("Ayo belajar Python") 6 | print('Belajar Python Sangat Mudah') 7 | 8 | #tipe data Integer 9 | print(20) 10 | 11 | #tipe data Float 12 | print(3.14) 13 | 14 | #tipe data Hexadecimal 15 | print(9a) 16 | 17 | #tipe data Complex 18 | print(5j) 19 | 20 | #tipe data List 21 | print([1,2,3,4,5]) 22 | print(["satu", "dua", "tiga"]) 23 | 24 | #tipe data Tuple 25 | print((1,2,3,4,5)) 26 | print(("satu", "dua", "tiga")) 27 | 28 | #tipe data Dictionary 29 | print({"nama":"Budi", 'umur':20}) 30 | #tipe data Dictionary dimasukan ke dalam variabel biodata 31 | biodata = {"nama":"Andi", 'umur':21} #proses inisialisasi variabel biodata 32 | print(biodata) #proses pencetakan variabel biodata yang berisi tipe data Dictionary 33 | type(biodata) #fungsi untuk mengecek jenis tipe data. akan tampil yang berarti dict adalah tipe data dictionary 34 | 35 | -------------------------------------------------------------------------------- /python_tingkat_lanjut/read_operation.py: -------------------------------------------------------------------------------- 1 | import PyMySQL 2 | 3 | # Open database connection 4 | db = PyMySQL.connect("localhost","testuser","test123","TESTDB" ) 5 | 6 | # prepare a cursor object using cursor() method 7 | cursor = db.cursor() 8 | 9 | # Prepare SQL query to INSERT a record into the database. 10 | sql = "SELECT * FROM EMPLOYEE \ 11 | WHERE INCOME > '%d'" % (1000) 12 | try: 13 | # Execute the SQL command 14 | cursor.execute(sql) 15 | # Fetch all the rows in a list of lists. 16 | results = cursor.fetchall() 17 | for row in results: 18 | fname = row[0] 19 | lname = row[1] 20 | age = row[2] 21 | sex = row[3] 22 | income = row[4] 23 | # Now print fetched result 24 | print ("fname = %s,lname = %s,age = %d,sex = %s,income = %d" % \ 25 | (fname, lname, age, sex, income )) 26 | except: 27 | print ("Error: unable to fetch data") 28 | 29 | # disconnect from server 30 | db.close() 31 | -------------------------------------------------------------------------------- /python_dasar/operator_aritmatika.py: -------------------------------------------------------------------------------- 1 | #file /python_dasar/operator_aritmatika.py 2 | 3 | #OPERATOR ARITMATIKA 4 | 5 | #Penjumlahan 6 | print(13 + 2) 7 | apel = 7 8 | jeruk = 9 9 | buah = apel + jeruk # 10 | print(buah) 11 | 12 | #Pengurangan 13 | hutang = 10000 14 | bayar = 5000 15 | sisaHutang = hutang - bayar 16 | print("Sisa hutang Anda adalah ", sisaHutang) 17 | 18 | #Perkalian 19 | panjang = 15 20 | lebar = 8 21 | luas = panjang * lebar 22 | print(luas) 23 | 24 | #Pembagian 25 | kue = 16 26 | anak = 4 27 | kuePerAnak = kue / anak 28 | print("Setiap anak akan mendapatkan bagian kue sebanyak ", kuePerAnak) 29 | 30 | #Sisa Bagi / Modulus 31 | bilangan1 = 14 32 | bilangan2 = 5 33 | hasil = bilangan1 % bilangan2 34 | print("Sisa bagi dari bilangan ", bilangan1, " dan ", bilangan2, " adalah ", hasil) 35 | 36 | #Pangkat 37 | bilangan3 = 8 38 | bilangan4 = 2 39 | hasilPangkat = bilangan3 ** bilangan4 40 | print(hasilPangkat) 41 | 42 | #Pembagian Bulat 43 | print(10//3) 44 | #10 dibagi 3 adalah 3.3333. Karena dibulatkan maka akan menghasilkan nilai 3 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

3 |
4 | ----------------- 5 | 6 | **Belajarpython** adalah situs tutorial pemrograman Python bahasa Indonesia. sedangkan Python sendiri adalah bahasa pemrograman interpretatif multiguna. Tidak seperti bahasa lain yang susah untuk dibaca dan dipahami, python lebih menekankan pada keterbacaan kode agar lebih mudah untuk memahami sintaks. Hal ini membuat Python sangat mudah dipelajari baik untuk pemula maupun untuk yang sudah menguasai bahasa pemrograman lain. 7 | 8 | Pada tutorial ini Anda akan mempelajari dasar pemrograman bahasa Python. 9 | 10 | **Jika Anda ingin membaca seluruh tutorial silahkan menuju ke [belajarpython.com](http://www.belajarpython.com).** 11 | 12 | ## Tutorial Pemrograman Python Bahasa Indonesia 13 | 14 | Dibawah ini adalah syllabus tutorial Python : 15 | 16 | **Pendahuluan** 17 | * [Memulai Python](http://www.belajarpython.com/#memulai-python) 18 | * [Instalasi Python](http://www.belajarpython.com/2015/05/instalasi-python.html) 19 | * [Menjalankan Python](http://www.belajarpython.com/2015/05/menjalankan-python.html) 20 | * [IDE Python](http://www.belajarpython.com/2015/05/integrated-development-environment-ide.html) 21 | 22 | **Python Dasar** 23 | * [Hello World Python](http://www.belajarpython.com/2015/05/hello-world-python.html) 24 | * [Komentar Python](http://www.belajarpython.com/2015/05/komentar-python.html) 25 | * [Tipe Data Python](http://www.belajarpython.com/2015/05/tipe-data-python.html) 26 | * [Variabel Python](http://www.belajarpython.com/2015/05/variabel-python.html) 27 | * [Operator Python](http://www.belajarpython.com/2015/05/operator-python.html) 28 | * [Kondisi If Python](http://www.belajarpython.com/2015/05/kondisi-if-python.html) 29 | * [Kondisi If Else Python](http://www.belajarpython.com/2015/05/kondisi-if-else-python.html) 30 | * [Kondisi Elif Python](http://www.belajarpython.com/2015/05/kondisi-elif-python.html) 31 | * [Pengulangan For Python](http://www.belajarpython.com/2015/05/pengulangan-for-python.html) 32 | * [Number Python](http://www.belajarpython.com/2015/05/number-python.html) 33 | * [String Python](http://www.belajarpython.com/2015/05/string-python.html) 34 | * [Lists Python](http://www.belajarpython.com/2015/05/lists-python.html) 35 | * [Tuples Python](http://www.belajarpython.com/2015/05/tuples-python.html) 36 | * [Dictionary Python](http://www.belajarpython.com/2015/05/dictionary-python.html) 37 | * [Tanggal dan Waktu Python](http://www.belajarpython.com/2015/05/tanggal-dan-waktu-python.html) 38 | * [Fungsi Python](http://www.belajarpython.com/2015/05/fungsi-python.html) 39 | * [Modul Python](http://www.belajarpython.com/2015/05/modul-python.html) 40 | * [File I/O Python](http://www.belajarpython.com/2015/05/input-output-python.html) 41 | * [Exception Python](http://www.belajarpython.com/2015/05/exception-python.html) 42 | 43 | **Python Tingkat Lanjut** 44 | * [Objek dan Class](http://www.belajarpython.com/2015/05/objek-dan-class-python.html) 45 | * [Akses Database](http://www.belajarpython.com/2015/05/akses-database.html) 46 | --------------------------------------------------------------------------------