[Cloud102] # 1 Get Started with Python (Part 1 Python First Steps)

AGENDA 0. Introduction

  1. Python on a black screen 2.Jupyter Notebook
  2. Python first step
  3. A little derailment
  4. Reference link

0. Introduction

Last time, due to various reasons, I did hands-on with GCP (Google Cloud Platform). This time I'm going back to the original Python hands-on (so last time it was # 2, but this time it's # 1: stuck_out_tongue_closed_eyes :)

1. Python on a black screen

Last time, in GAE hands-on (*), we deployed a Python web app to GAE from the terminal screen (black screen: sweat :) using a Cloud Shell instance. That said, the app to deploy was just copied with git clone, and I haven't seen any Python programs, so first, let's touch Python in the Cloud Shell environment we used last time.

(*) [Cloud102] # 2-2 Let's start GCP (second half: GAE edition) http://qiita.com/nagahisa/items/a3033b203fa929c8d7ab

(1) Launch of Cloud Shell

-Log in to the GCP console with the account you created last time and launch the Cloud Shell that everyone loves.

002-2.JPG

・ The previous GAE program remains. 004.JPG

-Create a suitable working directory (~ / 20161216-python in this example) and move to it (also check the Python path).

010-2.JPG

(2) python interpreter

When executed with no arguments, the python (python3) command operates as an interpreter environment that sequentially executes user input. It is called REPL (Read-eval-print loop). http://d.hatena.ne.jp/keyword/REPL

Now try the following with the python REPL:

x = 10
y = 20
print ( x + y )

-Start python REPL (>>>> is the display waiting for user input) 010.JPG

-Run a python program 011.JPG

To end the REPL, in addition to executing the quit () function as shown on the screen, press Ctrl-D.

(3) Creating a python program

In the last hands-on, I didn't dare to touch on how to edit files on Cloud Shell, and asked them to use nano / vi etc., but a web editor has appeared in Cloud Shell! http://googlecloudplatform-japan.blogspot.jp/2016/10/cloud-shell.html

This time, using this code editor, create a python program called test.py in the working directory created earlier.

・ Start code editor 005.JPG

・ This screen will appear in another tab of the browser. 006.JPG

・ Move the directory 007.JPG

・ Choose to create a new file 008.JPG

-Enter the file name (test.py here) 009.JPG

・ After writing the contents of the following file in the right pane, save the file

x = 10
y = 20
print ( x + y )

012.JPG

-Check that the file is created, specify the file as an argument of the python command, and execute it. 013.JPG

・ Magic so that it can be executed only by the file name 014.JPG

You can write a REPL or * .py file like this to study, but the black screen is not popular with young people: sweat: So, I will try using jupyter notebook which can do the same thing + alpha in the browser.

2.Jupyter Notebook

(1) What is Jupyter notebook?

As usual, the explanation is omitted. There is a lot of Japanese information, so let's check it out. I used to call it ipython notebook, so you can google it there.

Head family site http://jupyter.org/ 015.JPG

If you just want to try it a little, you can try it from the button below on the main site. (Go to https://try.jupyter.org) 016.JPG

(2) Construction of jupyter notebook server

Is an interesting hands-on, but it's not directly related to studying Python, so if you're interested, try the following (an example of using an instance of AWS Free Tier and GCP Cloud Shell).

[Cloud102] # 1 Let's get started with Python (Part 2 Jupyter Notebook Construction AWS Edition) http://qiita.com/nagahisa/items/92b5fd1cd983751182bb

[Cloud102] # 1 Let's get started with Python (Part 3 Jupyter Notebook Construction GCP Cloud Shell Edition) http://qiita.com/nagahisa/items/6b11d9edab2b6160ad26

Since jupyter notebook is often used in data science systems that are popular these days, this time I will use the one that comes with Microsoft's Azure Machine Learning Studio (free: grin :)

(3)Azure Machine Learning Studio

Azure ML Studio is a free data science tool (without a lot of machine learning). Of course, it is originally an easy-to-use tool group for opportunity learning, but since jupyter notebook is also included, we will use it.

・ If you do not have a personal Microsoft account yet, register from the following. https://www.microsoft.com/ja-jp/msaccount/signup/default.aspx 024.JPG

· Sign In to Azure ML Studio with your Microsoft Account. https://studio.azureml.net 020.JPG

・ If you just want to use it for a while, 8H Evaluation is fine, but this time, register in "Free Workspace" in the middle. 021.JPG

・ If a screen like this appears, it's OK 023.JPG

(4) How to use jupyter notebook

-Move to "NOTE BOOK" in the left pane. 025.JPG

-Since the notebook can be uploaded or newly created, select "Blank notebook" for Pytho3 from "+ NEW" here. 030.JPG

-Give an appropriate Notebook name (20161216-Python3 below). 031.JPG

・ This is the screen. 032.JPG

I will write comments (Markdown) and program code (Code) in this Notebook. First, let's write and run a simple comment and a simple program.

In addition, it would be helpful if you could refer to the following "proper" usage instructions: sweat:

http://pythondatascience.plavox.info/python%E3%81%AE%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83/jupyter-notebook%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86/

-The first cell is "Code", so change it to "Markdown" 033.JPG

-Write a comment in Markdown format in the cell, and after inputting, press Ctrl + Enter in the cell. (You can also use the Run button) Markdown will be interpreted and displayed. (The following is before execution)

##1.The first Jupyter Notebook


 ![034.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/c3f58870-8622-c7f3-c834-8d31f36dc3fb.jpeg)

 -Add a cell with the "+" button and write the program with "Code" as it is
 ![035.JPG](https://qiita-image-store.s3.amazonaws.com/0/79389/0778f643-6d3d-a4db-bad1-48df777b7ba1.jpeg)

 -Execute the program with Ctrl + Enter.
 ![036.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/a1f4917c-8de3-e638-de38-ecf922c01b42.jpeg)

 You can create a comment program program execution result as one notebook like this.

 ・ Save the created notebook
 ![037.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/a5db765c-ffa4-eddc-de50-559324ab29eb.jpeg)

 ・ Close Notebook and return to the list
 ![039.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/1b33bc21-1bc0-f5d7-5fb3-c71158b57090.jpeg)

 From this list you can open and update the notebook you are creating, import a notebook created by someone else, or download a notebook.

 The jupyter notebook supports not only Python but also "R" which is often used in statistical processing, so if you are good at Excel, you may want to study from "R". (If you wish, we will also plan R Hands On)

# 3. Python first step

 Although I say Python hands-on, I will not explain Python grammar etc. (I can not do it: sweat_smile :). Please study at the reference link later.

## (1) Sequential / branch / iteration

 In general, a program progresses in three actions (sequential, branching, and iterative).
 ・ Sequential: Execute in order from top to bottom (already done)
 -Branch: Change the process according to certain conditions.
 -Repeat: Turn around to process the same thing.

 Please copy and execute while looking at the image below (I do not dare to post the source: smile :)
 ![040.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/eb2c3edc-5c62-fdd2-856f-c08b5374ede9.jpeg)
 ![041.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/4bc64206-34b3-fedb-f825-042c79543060.jpeg)
 ![042.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/329c5d27-238a-2ce2-a496-0dd236ab7973.jpeg)
 ![043.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/49ed9609-724a-48ee-f9dc-18c638d19f1e.jpeg)

## (2) type

 In the above example, the value (10, "fine") is assigned to the variable (x, feel) like x = 10, feel = "fine", but these have "types".
 You can check the type with type (), so let's try various things by referring to the following.
http://www.tohoho-web.com/python/types.html 
 ![045.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/71bbd7a6-8b5d-1f7b-f421-daaa6da4b263.jpeg)

## (3) List, tuple, dictionary

 Python also has types such as lists, tuples, and dictionaries.
 Let's try various things with reference to the following.
http://www.tohoho-web.com/python/list.html

## (4) Function

 It's similar to the "function" you learned in mathematics, but it's essentially a little different. Experienced people may know the term "subroutine", but it is a mechanism to make frequently used processes (routines) reusable.

 Let's try various things with reference to the following.

http://www.tohoho-web.com/python/function.html#function
 ![046.JPG](https://qiita-image-store.s3.amazonaws.com/0/79389/ea6a6863-a7ac-3e10-7488-a59529c0c38c.jpeg)

## (5) Packages and modules

 There are many useful "modules" in Python that you can import and use.
 For example, in mathematics, you can use the math module to use love triangles.

 ![047.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/b65f9714-5cbb-4f72-0dba-9c0c43bc53f4.jpeg)

 In many cases, multiple modules are published as a package, and you may specify which module in the package to import.
http://www.tohoho-web.com/python/module.html

## (6) Feel a little statistical processing

 Let's touch on statistical processing by copying the following.
 ![048.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/42ecbe63-f48b-b79f-9ea2-59ebcbfa468f.jpeg)

## (7) Javascript can also be used
 Reference: http://enakai00.hatenablog.com/entry/2016/12/10/141301

 ![JS1.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/72c9b2ca-d6ab-d986-41f2-2a8c5417c154.jpeg)

 ![JS2.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/cf3de7fe-3353-10c0-39c6-66979ceb1919.jpeg)

 Let's do this as well.
 Easy analysis environment construction using Jupyter Notebook
https://datumstudio.jp/backstage/795

# 4. A little derailment

 The Python we are dealing with this time is a so-called "script language" that does not require compilation, but since GCP Cloud Shell also includes development environments for other languages, let's take a look. (Explanation is verbal: sweat_smile :)

 ・ The one that compiles into machine language
 ![gcc.JPG](http://qiita-image-store.s3.amazonaws.com/0/79389/19a4d720-bb58-e752-d517-a8e24aa43e9c.jpeg)

 ・ The one that compiles to an intermediate language
 ![java.JPG](https://qiita-image-store.s3.amazonaws.com/0/79389/3734a5fc-a028-1d27-b782-7101cb8266cb.jpeg)


# 5. Reference link

 I haven't studied grammar properly (type to look up when needed: sweat_smile :), but there are many good books and good sites out there that are studying properly.
 Here are some of the free ones that came out of Gugu.

 (1) Python tutorial
 The contents of this book are published on the Web
https://www.amazon.co.jp/exec/obidos/ASIN/4873117534/take1103-22/

http://docs.python.jp/3.5/tutorial/

 (2) Dive Into Python 3 Japanese version
 The first one is almost the same, but this one is a little more advanced.
http://diveintopython3-ja.rdy.jp/

(3)Python Boot Camp Text
http://pycamp.pycon.jp/

 (4) Introduction to Python (referred to in this content)
http://www.tohoho-web.com/python/index.html

 (5) Home tutorial
http://docs.python.jp/3.5/tutorial/

 Finally:

 As I said to those who participated in the first half of FY16 course (Cloud101), I think that ICT technology including programming is the same as my lover. How much time you spend will be irreplaceable to you.

 "_ Your roses will be important only for the time you spend for them _" From the Prince of the Stars

Enjoy :v:








Recommended Posts

[Cloud102] # 1 Get Started with Python (Part 1 Python First Steps)
Get started with Python! ~ ② Grammar ~
[Cloud102] # 1 Let's get started with Python (Part 2 Jupyter Notebook Construction AWS Edition)
Get started with Python! ~ ① Environment construction ~
Link to get started with python
How to get started with Python
Get started with Python in Blender
Get Started with TopCoder in Python (2020 Edition)
How Python beginners get started with Python with Progete
[Blender x Python] Let's get started with Blender Python !!
Django 1.11 started with Python3.6
1.1 Getting Started with Python
[Python] To get started with Python, you must first make sure you can use Python.
Getting Started with Python
Get started with MicroPython
Get started with Python on macOS Big Sur
Get date with python
Getting Started with Python
A layman wants to get started with Python
[First API] Try to get Qiita articles with Python
I tried to get started with blender python script_Part 01
I tried to get started with blender python script_Part 02
Get country code with python
Image processing with Python (Part 2)
Studying Python with freeCodeCamp part1
Getting Started with Python Functions
Bordering images with python Part 1
Get started with Django! ~ Tutorial ⑤ ~
Scraping with Selenium + Python Part 1
Get Twitter timeline with python
Get started with influxDB + Grafana
Get Youtube data with python
Getting Started with Python Django (1)
First neuron simulation with NEURON + Python
Getting Started with Python Django (4)
Studying Python with freeCodeCamp part2
Getting Started with Python Django (3)
Image processing with Python (Part 1)
Get started with Django! ~ Tutorial ⑥ ~
Solving Sudoku with Python (Part 2)
Get thread ID with python
Image processing with Python (Part 3)
Getting Started with Python Django (6)
Scraping with Selenium + Python Part 2
Get stock price with Python
Get home directory with python
Get keyboard events with python
IfcOpenShell python bindings get started
Python3 | Getting Started with numpy
Getting Started with Python Django (5)
Get Alembic information with Python
Let's get started with Python ~ Building an environment on Windows 10 ~
Minimum knowledge to get started with the Python logging module
Get message from first offset with kafka consumer in python
Playing handwritten numbers with python Part 1
[Package cloud] Manage python packages with package cloud
Get reviews with python googlemap api
[Automation with python! ] Part 1: Setting file
Get started with MicroPython (on macOS)
Web scraping with Python First step
Getting Started with Python for PHPer-Classes