This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Survey

Rabu, 02 Maret 2011

Belajar Pemrograman Python [Sesi 3]

Setelah tahu sejarah python dan sedikit persiapan, kini saatnya untuk belajar......

1. Hello World
  • Ketikkan $ vim hello.py
  • Tekan 'i' pada keyboard
  • Ketik --> print "Hello World!"
  • Tekan 'esc' pada keyboard
  • Ketik --> :wq --> fungsinya untuk menyimpan berkas dan keluar dari editor vim
  • Ketik --> python hello.py --> untuk eksekusi berkas hello.py yang baru saja dibuat
  • $ python hello.py
    Hello World!

2. Aturan Penulisan
  • Indent

  • Baris berikut ini merupakan blok program pada Python
    print "Hello world !"
    print "Apa kabar dunia!"
    Kita tidak boleh menuliskannya seperti ini
    print "Hello world !"
    print "Apa kabar dunia!"
    karena pesan kesalahan seperti ini akan tampil
    $ python hello.py
    File "hello.py", line 2
    print "Apa kabar dunia!"
    ^
    IndentationError: unexpected indent
    kenapa salah? menurut Python, sebuah blok program harus berada dalam sebuah "margin". Pada baris kedua terdapat spasi yang berarti berbeda satu karakter dengan baris sebelumnya.

  • Baris Perintah

  • Menekan tombol enter pada keyboard berarti Kita akan membuat sebuah perintah baru di baris baru.

    Untuk baris yang terlalu panjang, Kita dapat menggunakan karakter backslash (\) untuk memberitahu Python bahwa Kita akan menuliskan teks yang panjaaaang sehingga tidak berpindah baris.
    print "Hello World!"
    print "Apa kabar dunia!"
    print "Saat ini saya sedang\
    belajar bahasa pemrograman Python"
    Hasilnya
    $ python hello.py
    Hello World!
    Apa kabar dunia!
    Saat ini saya sedang belajar bahasa pemrograman Python
  • Keterangan Program (komentar)

  • Untuk membuat satu baris komentar, Kita dapat menggunakan tanda pagar (#)
    print "Hello World!"
    print "Apa kabar dunia!"
    print "Saat ini saya sedang\
    belajar bahasa pemrograman Python"
    #kalau sedang belajar jangan main-main dulu yaaa
    print "Semangat"
    Hasilnya
    $ python hello.py
    Hello World!
    Apa kabar dunia!
    Saat ini saya sedang belajar bahasa pemrograman Python
    Semangat
    Untuk komentar yang lebih dari 1 baris, gunakan 3 tanda kutip ganda (""")
    print "Hello World!"
    print "Apa kabar dunia!"
    print "Saat ini saya sedang\
    belajar bahasa pemrograman Python"
    #kalau sedang belajar jangan main-main dulu yaaa
    print "Semangat"
    """karena sudah mendapat semangat
    bagaimana kalau saya mengucapkan
    terima kasih"""
    print "Terima kasih"
    Hasilnya
    $ python hello.py
    Hello World!
    Apa kabar dunia!
    Saat ini saya sedang belajar bahasa pemrograman Python
    Semangat
    Terima kasih

Belajar Pemrograman Python [Sesi 2]

Persiapan dulu

Bumbu :
  1. Distro BlankOn Linux : dapat diunduh gratis di http://www.blankonlinux.or.id/
  2. Python : dapat diunduh gratis di http://www.python.org/Tautan
  3. terminal : sudah ada di dalam BlankOn Linux ( :P )
  4. vim editor : dapat diunduh dan belajar di http://www.vim.org/
Proses :
  1. Pasang Linux BlankOn
  2. Pasang python
  3. Buka terminal
  4. Hiasi terminal dengan vim editor
Hasilnya :

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More