Senin, 19 Februari 2018

#1 Introduction to Python

Introduction

Hello guys
In this article, i am going to share "how to use python" as well. knowing Python will be useful. Data scientist will need this program.

"A data scientist is someone who is better at statistics than any software engineer and better at software engineering than any statistician" - josh wills

There are two version of Python now, 2 and 3. the common differences is using ( ) with Print, raw_input become input etc. Windows user can download Python interpeter on Python.org
on this website, I use Python 3 !. Do not try to Copy-Paste the script for better result!

Using Python as Calculator

We can use Python with interactive mode as calculator. Note: 3 * 10^-2 is written 3e-2 in Python
>>> 3 + 3
6
>>> 1 * 2
2
>>> 5 / 5
1
>>> 1 - 2
-1 
>>> 10 % 3
1
>>> 2 % 3 
2 
>>> 6 % 3  
0
Arithematic operation in Python
+  Adding 2 object
-  substract object
*  multiplication
**  power
/  division
//  floor division
%  Remainder (mod)

Welcome Wolrd!

In this section, I use "PYCHARM" as the editor. You can use another editor to make .py programs. Now, we will start our tutorial with editor.
There are a lot of software for editor, Notepad++, Sublimetext 2 . To run the program, type
"python exercise1.py"

# exercise1.py
print ('Hello Turkiye!')
print \
('Hello Turkiye!')
After that, you can execute the program (Compile + run), and see how it works!

Adding Comment

We have to add "#" to make a comment. usually, it is used to add explanation or note to the code reader. You can see the example below!

# exercise2.py
# exercise2.py is the name
# This program is free
# This program will show you some example

print ('Hello Turkiye')

# print ('this program is a comment')

String
  1. Single Quote , 'Hello Turkiye'
  2. Double Quote, "Hello Turkiye"
  3. Triple Quote , ''' here is the example"
you can try!

# exercise3.py
# % will be used

print ('%s is the capital city of %s' % ('Jakarta', 'Indonesia'))

# we can make it as a set
print ('{0} is the capital city of {1}'.format('Jakarta', 'Indonesia'))

# we use f (float)
print ('this is made of float: %1.4f' % 1.4444)

Variable 

Giving example is the best way to explain

# exercise4.py
# Example of variable

x = -1
y = 2
z = 9

#test, capital,country is the name of function

test = x * y * z
capital = 'Jakarta'
country = 'Indonesia'

print ('the total is = %s' % test)
print ('%s is the capital city of %s' % (capital, country))

Data Type

In Python, you can find the data type. for example,

# integer
type(0)

# float
type(2,333)

# long
type(3e7)

# string
type(a)

we can find the data field by,

dir("a)

help(str)

Thank you, i will update the post as soon as possible





EmoticonEmoticon