C / C ++ programmer challenges Python (first step)

I've tried several times to learn Python, but all have failed. I'm finally feeling bad if I don't really remember it, so I'll try hard to study.

So, if you publish the process, it might be useful for other people.

textbook

"[Perfect Python](https://www.amazon.co.jp/%E3%83%91%E3%83%BC%E3%83%95%E3%82%A7%E3%82%AF%E3" % 83% 88Python-PERFECT-5-Python% E3% 82% B5% E3% 83% 9D% E3% 83% BC% E3% 82% BF% E3% 83% BC% E3% 82% BA / dp / 477415539X ) ”Will be used as a reference.

Python installation

Follow "Appendix A" to install Python on Windows. The download site is here.

According to the reference book, other libraries are often built with 32bit, so it is better to install the 32bit version, so

Windows x86 executable installer

I decided to download. You can download "python-3.6.0.exe", so run it to install it. It is better to check the "Add to path" check box. (By default, it will be installed very deeply)

Tips memo

From "Chapter 2", "Chapter 3", "Chapter 4", and "Chapter 5", there is a lot of discomfort, and the point that you have to remember this is a note as easy as possible. (The only thing you don't need to know is that it's confusing, so I'll skip it.)

Beginning of the beginning (environmental thing)

--A dedicated window (hereinafter referred to as "Python window") opens when python.exe is executed. image.png --"Quit ()" (or "Ctrl-Z") to close the Python window --Can also be executed with "python.exe file name" from a DOS window, etc. --If you want to execute the file, click here --The prompt is ">>>" --Basically specified in units of one line --If it is a function, it will be in continuous input mode. --If you insert a blank line, the continuous input mode will end. --Japanese is UNICODE (UTF-8) --In the Python window, if you want to know the variables and functions that have already been set, "locals ()"

In addition, I proceeded with studying in a two-window system consisting of a DOS window (for file execution) and a Python window (for input immediate execution).

A place with a lot of discomfort (C / C ++ programmer perspective)

--There is basically no such thing as "()" or "{}" --"()" Is used to specify the argument of the function ――It seems that you also use "{}", but you don't have to know it. --Block specification by indentation --Tab is good because indentation is hard to understand if it is a space ――But the recommendation is space --Do not add ";" at the end of the line --Comments start with "#", multi-line comments are enclosed in "'''" --No type declaration --There is no constant (define)

You should read PEP8 properly.

Type related

--Numerical variables are only "integers", "real numbers", and "complex numbers" --String type variables will be so if you insert a string --The array looks like a "list" (even different types can be inserted) --The empty declaration is "x = []" --It is difficult to understand that the insert is "list.insert (pos, value)" and the delete is "del list (pos)". --There seems to be a hand called "list.pop (pos)" --It seems that there is also a byte array --Map type (key-value type) exists under the name "dictionary type" --Actually, use "{}" with this guy --"Null" is "None"

function

--"Def" at the beginning of the function --":" After the function name ――Is this the meaning of "{" (though it doesn't close) --The return value is "return hoge" --It is also possible to return a function

Things to remember

--"Import" to load modules (like libraries) --The module that can be used in calculations is "math"

Bonus (grammatical)

--If statements are "if True:" "el if True:" "else:" --The for statement is "for item in x:" (iteration) --The elements of x enter item in order --Can also be obtained with x [n] --Let's also remember range () --while statement is "while True:" "else:" --There is also exception handling

Summary

I haven't been able to do anything at this level yet, but I feel that the place I had given up until now has been exceeded.

Recommended Posts

C / C ++ programmer challenges Python (first step)
C / C ++ programmer challenges Python (class)
Web scraping with Python First step
[GUI with Python] PyQt5-The first step-
The first step in Python Matplotlib
First time python
First Python 3 ~ First comparison ~
First time python
python C ++ notes
python, openFrameworks (c ++)
First Python ~ Coding 2 ~
First python [O'REILLY]
The first step in the constraint satisfaction problem in Python
First deep learning in C #-Imitating implementation in Python-
First Python 3rd Edition
Python C / C ++ Extension Pattern-Pointer
PyQ ~ Python First Steps ~
First Python image processing
AtCoder Beginner Contest 176 C Problem "Step" Explanation (Python3, C ++, Java)
Python points from the perspective of a C programmer
[Python] Python / Scikit-learn's first SVM
Next Python in C
The first step to getting Blender available from Python
First Python miscellaneous notes
C API in Python 3
ABC147 C --HonestOrUnkind2 [Python]
[Python] Chapter 01-01 About Python (First Python)
[Python] The first step to making a game with Pyxel
First Fabric (Python deployment tool)
Python--The first step in Pygal
Python, Java, C ++ speed comparison
PyTorch C ++ VS Python (2019 Edition)
ABC memorandum [ABC163 C --managementr] (Python)
First neuron simulation with NEURON + Python
Binary search in Python / C ++
Multi-stage selection (C # / Python) (old)
I tried Python C extension
Python started by C programmers
Reinforcement learning 4 CartPole first step
ABC188 C problem with python3
ABC187 C problem with python
Differences C # engineers felt when learning python for the first time