Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PYTHON 101

PYTHON 101

Python Introduction at KSL UR

Vicky Vernando Dasta

March 25, 2017
Tweet

More Decks by Vicky Vernando Dasta

Other Decks in Programming

Transcript

  1. About • student @ dept. of physics UR • founder

    of KSL UR • github.com/vickydasta • dasta.me
  2. About Python (python.org) • guido van rosum (1997) • interpreted

    language • multipurpose • oop (everything is object) • easy to learn • dynamic typing • batteries included • case sensitive
  3. Things we can build • machine learning (setruk) • computer

    vision • search engine (banyol) • web app (laporhoax.herokuapp.com) • web service (github.com/vickydasta/aha) • embedded system (micropython) • security/forensic tools (sqlmap, angr) • many more...
  4. Data Structure • Integer • List • String • Float

    • Boolean • Dictionary • Tupple
  5. Integer num = 12 num = num + 12 integer

    length only depends on memory size (as long as the memory can handle it, python still can do the job)
  6. List sequence of data example: box = [1, 2, 3,

    4] # create new list box[0] # get item on index 0 box.append(1) # add new item box.remove(1) # remove item on index 1
  7. Dictionary named list. JSON like data structure (key-value) example: user1

    = {“name”: “ksl-ur”, “password”: “123”} user1[“name”] # get value with key “name” user1.keys() # get all keys
  8. Tupple immutable list. once created, can’t: - add - remove

    example: box = (“apple”, “orange”) apple.append(“kiwi”) # error
  9. We’re going to learn • Variables • Logical operation •

    Number operation • Looping • Function • Control Flow • Error handling • String operation • File I/O • Coding Style (pep8)
  10. Logical Operation • 1 == 1 # equals • 1

    > 2 # greater than • 1 < 2 # smaller than • 1 <= 2 # smaller and equals • 1 >= 2 # greater and equals • 1 & 1 # and • 1 | 2 # or
  11. Number Operation • 1 + 1 # addition • 1-2

    # reduction • 1 / 2 # division • 1*2 # multiply • 1 % 2 # modulo • 2 ** 2 # power
  12. String Operation • we can do: - multiplication - addition

    example: “hello”+”world” “hello world”*5
  13. for to iterate over an iterable object • for a

    in range(10): print a • for item in fruits: print item • for index, item in enumerate(fruit): ...print index, item
  14. while logic based loop. only do the loop if the

    statement returns true. while 1==1: ...print ‘hello!’ else: ...print ‘hola!’
  15. control flow if 1 > 0: print “!!!” if 1

    > 2: print “hola” else: print “holi” if 1 > 2: print “hola” elif 1 > 3: print “holu” else: print “holi”
  16. File I/O - open a text file, and print the

    content - open a text file, and write a content into it with open(‘filename’, ‘r’) as f: ...for text in f: …...print text with open(‘filename’, ‘w’) as f: ...f.write(‘hello world!’)