#9 Class Instance Python/

Python allow to object oriented programming (OOP). That is make a code writing so fast. Because object oriented programming reuse another code that containt formula and data.

As OOP, main emphasis of Python is on object. Another progamming paradigm, procedure oriented programming stress on function.

Object is set of data (variable) and method (functions) that can work on data. To create an object, programmer create a blueprint, first, then create object. The blueprint is named a class. Then we can make multiple object based on a classs. That is make coding faster, easier to write and read.

Class is reusable object as blue print that contain attribut and methods. A class is a description of an object’s characteristics.

Some book say that class is also an object. So, to prevent confusion, some writer give different name for object, it is instance. Instance is an object that is create based on class/ or bluprint.

Create Class

Usually, people called create class as class definiton. Inside the class, there are data attributes and procedures. 

The syntax of class definition is:

class MyClass:
    statement or instruction

That is formula to crate class. Example of simple class is :

class MyClass:
  x = 5
  def func(self):
      print (hello)

That example is a class that have a attribute x = 5 and also method or function. The function is func(). 

Parameter and argument

Class have (1) data or property /attribute and also (2) methods or function. Function have characteristics in python. It have parentheses (). Inside parentheses, there is parameters. Parameter are specified value after the function name. Parameter in inside the parentheses. We can give empty parameter, one, two and more. We can add as many parameters as you want. To create multiple parameter we can just separate them with a comma

Value of parameter is argument. If your parameter is “name”, the argument is “John”, “Mary” and so on.

We can also give default value parameter. For example,

def my_function(country= "United States"):
  print("I am from " + country)


If the argument of function is empty, It will show default argument or parameter value.

Create an instance

To reuse a class, we can create instance of class. To reuse a class, we can import the class first, if the class in different file. If a class in same file with an instance, import is not necessary.

import MyClass

newinstance = classname.function(parameter)

Each instance of a class has characteristics of class. Each instance have clone datas and methods of class. Instance also can modify data without destroy class. So, class can be starting point to create new instance. 

Why this blog talk about Python?

After reading Jamal Khashoggi case, I aware that economic and political ambition sometimes is blind to another consideration outside the ambition. The consideration includes a love of human and environment. Ambition makes human to be packman that cost on another human and environment.

That is not just coinsidence, but logical consequencies if they think that ambition is has to be reach at all cost.

So, I didn’t want to only talk about business in this blog. I want to talk about multiple beautiful things in our world. Not just business. I will to also to talk about programming that connects to the internet, I choose python. Python have capabilities to manage big data.

To Monitor Bot and Big Data

Why I talk about programming and big data. Big data and the bot can help the packman to manipulate and violate human and environment. So I need to monitor and update about big data and the bot. It help to monitor bad effect of big data.

To Reduce Excessive Ambition

The second point is it is good for the human to reduce the priority of one side ambition. Political and economic ambition only is one side ambition. I think it is good to find another simple pleasure. So we can recode one side ambition. Python is one of simple pleasure.

That is why I will talk about learning python and big data. Python is one of simple pleasure that I hope reduce excessive ambition.

To Handle Business Task

The third point is programming can help to handle the business task. Programming also helps us with getting information that matters. I have an idea to make an easier business task, for example: create a business plan, monitor opportunity, and threat.

Python is one of programming language on a computer. If we write in python language, we can give instruction to a computer. The computer can do our job, include big or repetitive jobs. Without programming language, the computer cannot obey our instruction. Python is one of programming language among another programming language like C+, Java, Visual Basic, R, Ruby and so on.

#8 Loop Statement in Python

Loop statement in Python executes repeatedly the statement as long as a given condition is true. A unique feature of loop statement is repetition.

Loop and conditional statement have the similar and different point. Different than a conditional statement, the loop statement will repeat if match the condition. Similar to the conditional statement, the loop statement has a condition to execute. Sometimes, the programmer said it repetition structure or iteration.

The Syntax of Loop Statement

Syntax of loop statement is

>>> while condition :
        statement #if meet condition

The statement will repeat if condition is true.

#7 Conditional Statement in Python

Why Auto driver that python makes can make an adjustment to an unpredictable situation. For example, if a car faces another stopped car in front of it, the auto driver can also stop accordingly. That is amazing.

Python can do that, because python have conditional statement or If statement.

The conditional statement is useful for creating a decision structure. Decision depends on condition. This allows a program to create more than one scenario. The if statement has an instruction for one ,, and another different instruction for another condition.

If statement have component, boolean and relational expression to check condition. Beside that, this if statement also have instruction to execute if condition as request.

Boolean and Relational Expression

A Boolean value has two value, True or False. Statement that use this value is Check Statement. Check Statement is statement that evaluate whether the statement true or false. In English language, is A is same with B? in Python language, A==B. faces statement tests an expression to determine whether it is true or false.
Boolean value is named after George Boole formulate some rules for reasoning about and combining this binary value (True and False). It is suit for computer that have binary value, 0 and 1.

We can get list of boolean value in Python by type : dir(True).

>>> dir(True)
       ['abs', 'add', 'and', 'class', 'cmp', 'coerce', 'delattr', 'div', 'divmod', 'doc', 'float', 'floordiv', 'format', 'getattribute', 'getnewargs', 'hash', 'hex', 'index',
       'init', 'int', 'invert', 'long', 'lshift', 'mod', 'mul', 'neg', 'new', 'nonzero', 'oct', 'or', 'pos', 'pow', 'radd', 'rand', 'rdiv', 'rdivmod', 'reduce', 'reduce_ ex', 'repr', 'rfloordiv', 'rlshift', 'rmod', 'rmul', 'ror', 'rpow', 'rrshift', 'rshift', 'rsub', 'rtruediv', 'rxor', 'setattr', 'sizeof', 'str', 'sub', 'subclasshook', '_
       truediv_', 'trunc', 'xor', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real'] "

That is a list of several function related to boolean type data.

Another alternative, we can read the documentation by type “help(True) ” or “help(False) in python command line.

>>> help(True)
       Help on bool object:class bool(int)
  |  bool(x) -> bool
  |  Returns True when the argument x is true, False otherwise.
  |  The builtins True and False are the only two instances of the class bool.
  |  The class bool is a subclass of the class int, and cannot be subclassed.
  |  Method resolution order:
  |      bool
  |      int
  |      object"

Usually, Boolean operator use equal (==), greater(>) and less to determine whether a specific relationship True or False.

> Greater than
>= Greater than or equal to
< Less than
<=Less than or equal to
== Equal to
!=Not equal to

Boolean Value in Conditional Expression

How boolean value in conditional expression. In Python language, the syntax of Conditional is like this

>>> If condition :

Condition in the syntax is boolean statement. That is something that computer can evaluate whether that is True or False. True or False in the term of meet condition. That is not about morality or epistemology.

In flowchart, Conditional Statement use symbol like this.

Logical Operator

Python also accommodate more complicated expression in boolean mode. There are logical operator to combine simpler boolean operator. The logical operator is” and”, “or” and “not”.

“and” Operator

The and and or combine two boolean expression. “And” operator evaluate expression as true only if the both expression is true. The truth table is like this.

XYX and Y

“or” Operator

or operator evaluate two statement. Then if one or more statement is true, the or operator return to True.

XYX or Y

“not” Operator

not operator can apply to one statement or more.
if the not operator apply to True value, it flowcharts to False.

Xnot X

Conditional Execution

A conditional statement has a ability to check condition and execute instruction or statement based on condition.
The syntax is like below.

>>> if True: # This is always True,
        pass # so this is always executed, but it does nothing
>>>  else:

Chained conditionals/ nested decision

if we need more than two condition and more than two instruction, python also accommodate. Chained or nested decision structure check more than one condition.

Notation of chained conditional statement is like this.

That is the conditional statement inside another conditional statement.