Today we are talking about the Python language.
Let's do the programming language in earnest. (Although JavaScript up to yesterday is also a programming language)
For installing programming tools Please refer to here.
This language is not only in educational settings Because it is used in many sites Not just learning and research Because it is very useful for doing business Great for first-time learning languages.
As a characteristic of the programming language ・ Very simple and easy-to-understand grammar ・ Abundant reusable programs called libraries ・ Abundant examples of program implementation about it.
Ranked in the top 3 in terms of programming language popularity It will be the language that is getting the most attention right now.
In particular, statistical analysis, machine learning, and AI-related researchers are almost always I am learning Python and the demand for it is increasing in Japan.
Once you've learned Python again You will soon be able to learn other languages as well.
I think it is suitable for a language that you learn for the first time. Perhaps by the end of this course, I was interested in other languages as well. The desire to learn more and more I'm hoping that it will increase.
Let's learn programming with Python as the main axis.
Click here for the explanation video
Once you have Anaconda installed You should be able to use Jupyter Notebook.
** How to start Jupyter Notebook **
windows: Find Anaconda Prompt in the program and start it.
macos: Find the terminal in the application and start it Type the following command and press the enter key
jupyter notebook
OK if the following screen is launched in the browser
After starting jupyter notebook
http://localhost:8888/tree
You can access the basic screen of jupyter notebook with.
** How to operate on the basic screen **
The operation on the basic screen is as follows.
Upper right of the screen: Click New to create a new one -Text File ・ Folder -Python (notebook for executing Python) Click Upload to add (load) another file
Upper left of the screen: Click the square button displayed on the left side of the folder or file to select it After selection, you will be able to rename or delete. ![alt] (https://d2l930y2yx77uc.cloudfront.net/production/uploads/images/10960529/picture_pc_906ed7a141c9108954c162e8c86f4be7.png)
** Create a new notebook **
Upper right of the screen: Click New ・ Python You can create a new notebook by selecting and clicking.
Operation with notebook Upper left of the screen: After creating a new one, the following screen will be displayed. You can operate the notebook from the menu at the top of the screen. The following are frequently used operations.
Program input and execution method The program is executed by entering the code in the input field called "cell". After inputting the program, Shift key + Enter key Alternatively, you can select and execute "Run Cells" from "Cell" at the top of the screen. (Shift key + enter key is the easiest) In the case of the bottom row, cells are added below after execution. Otherwise, the cell selection moves down.
If you want to execute from the top You can do everything from "Cell" at the top of the screen with "Run All".
Add, move, delete cells "Plus button" at the top of the screen or You can add cells from "Insert" with "Insert Cell". To move a cell, first click the cell to select it, You can move it by clicking the up and down arrows at the top of the screen. With the cell selected "Scissors" mark at the top of the screen or You can delete cells from "Edit" with "Cut Cells".
Save, convert and rename notebooks To save a notebook Do you click the "floppy mark" at the top left of the screen? Click Save and Checkpoint from the File menu. If you want to convert your notebook to another format You can convert to various formats by selecting "Download as" from the "File" menu. To rename a notebook Click on the notebook title Click Rename from the File menu to change it.
Notebook restart If you're running a program and something goes wrong You can fix it by restarting your notebook. "Restart" from the menu "Kernel" at the top of the screen Alternatively, select "Restart mark" to display the restart screen. Click "Restart" to restart.
)
The basis of programming is "operation". Calculation is to perform various calculations.
The basis of the program is
A program is basically a combination of letters and numbers. It is a mechanism that performs some kind of calculation and produces the result. Calculations are roughly divided into "character" and "numerical" calculations.
Four arithmetic operations
Addition(addition)) +
Subtraction(subtraction) -
Multiply(multiplication) *
division(division) /
Surplus(remainder) %
Exponentiation**
"Literal" refers to the numbers and letters used in calculations Symbols such as plus (such as +-) are called "operators".
Among them, the one used for the four arithmetic operations I read it as "arithmetic operator" (or algebraic operator).
Enter the following in the cell and see the result. To do this, press Shift + Enter.
#addition(Addition)
1+2
#subtraction(Subtraction)
1-3
#Multiplication(Multiply)
2*3
#I get an error because x cannot be used
2 x 3
#division(division)
10/3
#division(No remainder, truncation division)
10//3
#Exponentiation
2**3
#root
2**0.5
#Surplus(The remainder when broken)
5%3
#The priority of multiplication and subtraction is the same as that of math
2 * 3 + 4
"Literal" refers to the numbers and letters used in calculations Symbols such as plus (such as +-) are called "operators".
Among them, the one used for the four arithmetic operations I read it as "arithmetic operator" (or algebraic operator).
others ・ Bit operator -Assignment operator ・ Comparison operator ・ Boolean operator ・ Conditional operator There are many types of operators.
Handling of character strings is also an operation.
To express programming simply Those that perform magnificent string operations I think it can be expressed as.
** How to handle characters in Python **
To treat as a character string
Enclose in '
single quotes or "
double quotes
'First step'
"Second step"
Letters and numbers are different in the program If you do not enclose it, an error will occur.
Third step
NameError Traceback (most recent call last)
** How to display on the screen **
If you want to display characters on the program
Use the print function
.
In the function, what is put in () parentheses is called "argument".
print('that')
print('Well-balanced')
print('Yamamoto! !!')
that Well-balanced Yamamoto! !!
** Use single quotes and double quotes **
If you want to use single quotes for characters, enclose them in double quotes. If you want to use double quotes for characters, enclose them in single quotes.
print("moco’s kitchen")
print('this"What do you read?')
moco’s kitchen What do you read this "?
Characters can use the operators +
(add) and *
(multiply).
When added, concatenate character strings When calling, repeat the character string
print('Ostrich' + 'club')
print('I haven't heard' * 10)
Dacho Club I'm not listening I'm not listening I'm not listening I'm not listening I'm not listening I'm not listening I'm not listening I'm not listening I'm not listening I'm not listening
Characters and numbers cannot be handled together. An error will occur due to a grammatical error.
print('M' + 1 + 'I don't know')
TypeError Traceback (most recent call last)
If you enclose it in a single wort and treat it as a number You can avoid grammatical errors.
print('M' + '1' + 'I don't know')
M1 unknown
** How the print function works **
Since the print function will include the line feed code at the end
If you don't want to issue a line feed code
Add ʻend = and enter an alternative to the line feed code. If ʻend =''
, a blank is output.
print("Useless", end="")
print("Useless")
print("Useless", end="")
really useless Useless
comment
In Python, #
(pound sign) is a character that indicates the function of a comment.
Code after entering this will be ignored
You can use this to leave comments in the program. If you enter the comment in English, it's probably cool www
###Here is a comment
print('The above comment line has no effect at runtime') #Nothing happens even if I comment on such a place
#Also comment here
The above comment line has no effect at runtime
When you want to comment all together
For mac, hold down the command key
and the slash key
For windows, hold down the control key
and the slash key
A brief description of the tools for using the Python language I did only simple grammar.
Let's get it running right away.
76 days until you become an engineer
Otsu py's HP: http://www.otupy.net/
Youtube: https://www.youtube.com/channel/UCaT7xpeq8n1G_HcJKKSOXMw
Twitter: https://twitter.com/otupython
Recommended Posts