You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1

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.

You will become an engineer in 100 days ――Day 5 ――Environment construction ――Installation of program languages and tools

About the Python language

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.

How to use Jupyter Notebook

Click here for the explanation video

I'm sorry if it doesn't appear

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 alt

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 alt

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.

alt

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.

alt

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.

alt

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.

alt )

Calculation

I'm sorry if it doesn't appear

The basis of programming is "operation". Calculation is to perform various calculations.

The basis of the program is

  1. Input
  2. Calculation
  3. Output These three

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.

letter

I'm sorry if it doesn't appear

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) in () ----> 1 Third step NameError: name'Third step' is not defined

** 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) in () ----> 1 print ('M' + 1 +'Unknown') TypeError: Can't convert 'int' object to str implicitly

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

Summary

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

Author information

Otsu py's HP: http://www.otupy.net/

Youtube: https://www.youtube.com/channel/UCaT7xpeq8n1G_HcJKKSOXMw

Twitter: https://twitter.com/otupython

Recommended Posts

You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
You will be an engineer in 100 days ――Day 30 ―― Python ―― Basics of Python language 6
You will be an engineer in 100 days ――Day 25 ―― Python ―― Basics of Python language 2
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
You will be an engineer in 100 days --Day 34 --Python --Python Exercise 3
You will be an engineer in 100 days --Day 31 --Python --Python Exercise 2
You will be an engineer in 100 days --Day 65 --Programming --Probability 3
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
You will be an engineer in 100 days --Day 86 --Database --About Hadoop
You will be an engineer in 100 days ――Day 71 ――Programming ――About scraping 2
You will be an engineer in 100 days ――Day 61 ――Programming ――About exploration
You will be an engineer in 100 days ――Day 74 ――Programming ――About scraping 5
You will be an engineer in 100 days ――Day 73 ――Programming ――About scraping 4
You will be an engineer in 100 days ――Day 75 ――Programming ――About scraping 6
You will be an engineer in 100 days --Day 68 --Programming --About TF-IDF
You will be an engineer in 100 days ――Day 70 ――Programming ――About scraping
You will be an engineer in 100 days ――Day 81 ――Programming ――About machine learning 6
You will be an engineer in 100 days ――Day 79 ――Programming ――About machine learning 4
You will be an engineer in 100 days ――Day 76 ――Programming ――About machine learning
You will be an engineer in 100 days ――Day 80 ――Programming ――About machine learning 5
You will be an engineer in 100 days ――Day 78 ――Programming ――About machine learning 3
You will be an engineer in 100 days ――Day 84 ――Programming ――About machine learning 9
You will be an engineer in 100 days ――Day 83 ――Programming ――About machine learning 8
You will be an engineer in 100 days ――Day 77 ――Programming ――About machine learning 2
You will be an engineer in 100 days ――Day 85 ――Programming ――About machine learning 10
You will be an engineer in 100 days ――Day 60 ――Programming ――About data structure and sorting algorithm
You become an engineer in 100 days ――Day 66 ――Programming ――About natural language processing
You become an engineer in 100 days ――Day 67 ――Programming ――About morphological analysis
What beginners learned from the basics of variables in python
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
Test the number of times you have thrown a query (sql) in django
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
The basics of running NoxPlayer in Python
Become an AI engineer soon! Comprehensive learning of Python / AI / machine learning / deep learning / statistical analysis in a few days!
Basics of Python ①
Basics of python ①
Python: Deep Learning in Natural Language Processing: Basics
Basics of I / O screen using tkinter in python3
Japan may be Galapagos in terms of programming language
How to use Python Kivy ① ~ Basics of Kv Language ~
When you get an error in python scraping (requests)
How much do you know the basics of Python?
Basics of Python scraping basics
# 4 [python] Basics of functions
Basics of python: Output
If you draw an Omikuji with a probability of 1% 100 times in a row, will you win once?
Processing of python3 that seems to be usable in paiza
A liberal arts engineer tried knocking 100 language processes in Python 02
What beginners learned from the basics of variables in python
A liberal arts engineer tried knocking 100 language processes in Python 01
A liberal arts engineer tried knocking 100 language processes in Python 00
Quicksort an array in Python 3
Python is an adult language
Equivalence of objects in Python
python: Basics of using scikit-learn ①
Implementation of quicksort in Python
Basics of Python × GIS (Part 1)
Will the day come when Python can have an except expression?
Create an instance of a predefined class from a string in Python
How to know the internal structure of an object in Python