Let's write a Python program and run it

Overview

This article walks you through the steps of a beginner developing a coupon distribution service for the iPhone with a RESTful API and swift. It is a very detour implementation because it was implemented while examining the technical elements one by one.

For those who are new to programming as well as Python, programming based on modern fremework may be frustrating just by building an environment. So for the time being, I will introduce a method that makes it easy to experience writing and running a program. We're dealing with Python here. The computer is assumed to be a Mac.

procedure

Create a working folder

As a working folder, create a folder for saving programs under your home directory (user name folder). I created a folder to be my home directory / workspace / python-sample. We recommend that you use English characters for the folder name.

Check if Python is installed

For Mac, Python is installed from the beginning (as of Mac OS 10.15). The version is a little old, but there is no problem as long as it runs a basic program. Just in case, make sure that it is really installed.

If you are using a Mac, you can easily check it at the terminal. Terminal is a tool that corresponds to the command prompt in Windows. The terminal is usually stored in the application / utility. where-tarminal.png

Open a terminal and enter the following command to execute (press the Enter key). (The $ mark is displayed from the beginning, so do not enter it.)

$ Python -V

If you see the Python version, you already have Python installed.

Write python code in an editor

If the editor is Mac, you can use TextEdit and so on. If you are thinking of writing Python in earnest, it is convenient to install Visual Studio Code etc. is. It is available free of charge. Installation can be done in the same way as a normal application.

Now, let's write a program that displays standard characters.

print('Hello Python')

It's a simple one-line program. After writing, save it in the file created earlier, but there are two points to note at this time.

Run the program in the terminal and check the operation

Open a terminal and navigate to the folder where you saved the program. The command when moving is

$cd folder path

It will be. (The $ mark is displayed from the beginning, so do not enter it.)

For example, if you save the program in your home directory (user name folder) / workspace / python-sample, the location when you open the terminal will automatically be your home directory.

$ cd workspace/python-sample

It will be. "Cd" is a command used to move folders and is an abbreviation for change directory. When moving to the next higher folder

cd ../

Enter.

After moving to the folder where you saved the program, you can execute the program with the following command.

python filename.py

When executed, the result will be displayed in the terminal. The keyword "Hello Python" written in the program is displayed. (Hereafter, execution result) python-hello-run.png

With this flow, you can try Python programming like a sandbox even if you don't have a solid development environment.

Next, Create a virtual environment for pipenv and install Django

Recommended Posts

Let's write a Python program and run it
Make a Python program a daemon and run it automatically when the OS starts
[Python] Chapter 01-03 About Python (Write and execute a program using PyCharm)
Write a Caesar cipher program in Python
2. Make a decision tree from 0 with Python and understand it (2. Python program basics)
Periodically run a python program on AWS Lambda
Let's throw away JavaScript and write a web front end in Python!
A python program that resizes a video and turns it into an image
[Python] Concatenate a List containing numbers and write it to an output file.
Write a super simple molecular dynamics program in python
Let's make a Makefile and build it (super beginner)
I want to write in Python! (2) Let's write a test
Let's write python code that parses go code and generates go code
A program to write Lattice Hinge with Rhinoceros with Python
Let's run Excel with Python
Let's write python with cinema4d.
Write and read a file
Until you create a machine learning environment with Python on Windows 7 and run it
Temporarily save a Python object and reuse it in another Python
Associate Python Enum with a function and make it Callable
Write a python program to find the editing distance [python] [Levenshtein distance]
Let's create a PRML diagram with Python, Numpy and matplotlib.
Get a Python web page, character encode it, and display it
How to write a metaclass that supports both python2 and python3
Recursively get the Excel list in a specific folder with python and write it to Excel.
Python a + = b and a = a + b are different
Write a binary search in Python
[Python] Let's master all and any
Let's run "python -m antigravity" in python
[Python] Let's write briefly about comprehensions
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
[Python] return A [or / and] B
Let's make a graph with python! !!
Run a simple algorithm in Python
Write a batch script with Python3.5 ~
When writing a program in Python
Let's write a simple simulation program for the "Monty Hall problem"
How to install OpenCV on Cloud9 and run it in Python
[PEP8] Take over the Python source code and write it neatly
Build a detonation velocity website with Cloud Run and Python (Flask)
Try to write a program that abuses the program and sends 100 emails
Prepare a machine learning project format and run it on SageMaker
[Python] A program that creates stairs with #
Let's make a shiritori game with Python
[Python / Jupyter] Translate the comment of the program copied to the clipboard and insert it in a new cell
Let's write a program to solve the Rubik's Cube (Part 2: IDA * Search)
I made a payroll program in Python!
Deploy a Python app on Google App Engine and integrate it with GitHub
Write the test in a python docstring
How can I write a good program?
Let's write a simple DC current solver
Let's create a virtual environment for Python
Let's create a free group with Python
A memo with Python2.7 and Python3 on CentOS
Connect a lot of Python or and and
Write a short property definition in Python
Sh and py run after installing Python3
Write O_SYNC file in C and Python
Run the Python interpreter in a script