Wednesday, May 22, 2024

Python Beginner - Module 6 - Dave & Alison 01

Sampai juga kita di module ke 6 dan video ke 9 dari Dave Gray, pelajaran Python for beginner. 


Image Python for beginner (credit to Google)

Module 6, Chapter 1

Kita akan bicara tentang data.txt dan cara membukanya.

data.txt
hello
abc
123

kemudian data.txt dibuka file.read
with open('files/data.txt', 'r') as file:
    data = file.read()
    print(data)
Run Python File:
hello
abc
123
----------------------------------------------------

Module 6, Chapter 2
userInput = input('Enter your message : ')

with open('files/data.txt', 'w') as file:
    file.write(userInput)
Run Python File:
Enter your message : apa kabar

data.txt....> berubah:
apa kabar

w menjadi a
userInput = input('Enter your message : ')

with open('files/data.txt', 'a') as file:
    file.write(userInput + '\n')
Run Python File:
Enter your message : test

data.txt....> berubah:
apa kabartest

Run sekali lagi, berubah:
apa kabartest
 test2


Which of the following are file opening modes? Choose three.
- a+
- w+
- rb
-------------------------------------------------


Binary File:
- difficult to access
- not use python directly, but Pickle
- use dictionary : { }
- load ...> to read (r)
- dump ...> to write (w)

Which of the following file opening modes is used for binary files? Drag the correct answer into the space provided:
- wb
--------------------------

Classes


Module 6, Chapter .
subclass

Which of the following is written in the pascal case format? Choose one.
- ThisIsPascalCase
---------------------------------------------

Module 6, Chapter 5, 6, 7, 8

Di sini kita tentang variable & Methods

Which of these is a type of variable? Drag the correct answer into the space provided.
- instance variable

True or False: Every class method you construct in an object-oriented approach will always take "self" as an argument.
- True
-------------------------------------------

KIta akan membuat


The followings are the key points from this module:
The following are the file opening modes mentioned in the module:
 w, a, r, w+,a+, r+. -- These are used for text files.
WHILE:
 rb, wb. -- These are used for binary files. 
The pascal case is written as thus -- ThisIsPascalCase.
The following are the variable types mentioned earlier in the module: 
  • Instance variable.
  • Static variable. 
Polymorphism is the ability to accept multiple forms of objects into a specific class.
Every method you construct in an object-oriented approach take "self" as an argument. 







JJJJJJJJJJJJJJJJJJJJJJ

No comments:

Post a Comment