The contents of the Python tutorial (Chapter 3) are itemized.

Previous article: The contents of the Python tutorial (Chapter 2) are itemized

Introduction

Python3 Engineer Certification Basic Exam As a countermeasure, this is a personal memo that summarizes the contents of the Python tutorial (book) in easy-to-memorize bullet points.

Reference material

Python Tutorial: https://docs.python.org/ja/3/tutorial/ Chapter 3: https://docs.python.org/ja/3/tutorial/introduction.html Books: https://www.oreilly.co.jp/books/9784873117539/

"Chapter 3 Easy Introduction"

--Python3 Engineer Certification Basic Exam Score ―― 6/40 questions (15.0%) ☆☆☆ ★★ (importance: medium) --Theme --Comment --Variables --Numeric types and sequences (strings, lists) --Comparison operator

3.1 Use Python as a calculator

--Comment -** Comments ** are from the hash symbol # to the physical line. --OK even from the middle of the line. -** String literal ** (Quoted string) # inside is not interpreted as a comment. --Variables -** Variable ** is defined by assignment. --Use the equal sign = for substitution. --There is no variable declaration or variable data type specification. --An error will occur if you use an undefined (non-assigned) variable. --In interactive mode, the last entered expression is assigned to the ** variable _ ** (underscore).

3.1.1 Numerical value

――When numeric types are mixed in the operation of numerical values, integers are moved to float.

operator example
+
[Addition]
>>> 2 + 2
4
-
[Subtraction]
>>> 5 - 3
2
*
[Multiply]
>>> 4 * 8
32
/
[division]
>>> 17 / 3
5.666666666666667
%
[Surplus]
>>> 17 % 3
2
//
[Devaluation division]
>>> 17 // 3
5
**
[Exponentiation]
>>> 5 ** 2
25
Numeric type example
integer
[int]
4, 5, 20
Floating point number
[float]
3.1415, 1.4142
Decimal number
[Decimal]
10, 1000, 10000
Binary number
8 base
Hexadecimal
0b10 #2
0o10 #8
0x10 #16
Rational number
[Fraction]
1, 2, 3.45678
Complex number 3 + 5j

3.1.2 String

--Python's ** string ** is ** immutable ** and cannot be modified. -You can use "and'for ** quotes ** to get the same result. --If you don't use it as a quotation mark, you can put it in a string literal. --If you use it as a quotation mark, you can use it in a string literal by escaping it with ** backslash ** . -Can be output with the ** print () ** function. --String quotes are not output. --The end of the output has a newline \ n by default, but you can specify the end of the output with the keyword argument end. -** len () ** function returns string length. --If you add r before the quotation mark, it becomes ** raw string . --raw strings do not interpret special characters (\ n, \ r, etc.). -- Triple quotes ** ("" "or''') to write multiple lines of string literals. --If you want to disable line breaks, write a backslash \ at the end of the line. --Strings can be concatenated with +. --Concatenation with variables and expressions is also possible. --The character string can be repeated with *. --The enumerated string literals are automatically concatenated. --Automatic concatenation of variables and expressions with string literals is not possible. (Let's use +) --A part of the character string can be extracted by ** index specification ** (specified by serial number). --The index starts from 0. --Index-1 retrieves the penultimate character. --- 0 is the same as 0. --If you specify an index outside the range, an error will occur. -You can also specify the range by ** slicing **. The end point is excluded. --word [0: 2] Get index = 0 ~ 1 of #word --word [: 2] # Get index = ~ 1 of word --word [2:] # Get index = 2 ~ of word --Even if an index outside the range is included, no error will occur and the character string within the range will be taken.

3.1.3 List

-** List ** is a ** mutable **, and items can be modified. -Put items (values) in [] separated by commas. --Items of different data types can also be entered. (Usually the same) --Lists can be nested (listing items in the list). --As with strings, you can use indexing and slicing. --Indexing returns an item. --Slicing copies the list and returns a new list. --It is used when updating the list contents with a for statement (-> Chapter 4). --You can replace or clear items specified by indexing or slicing. --If cleared, the index will be packed. --Lists can be linked. --Items can be added to the end by the ** append () ** method of the list.

3.2 Programming, the first step

--Variables can be ** multiple assigned . --All right-hand equations are evaluated (from left to right) before substitution. --Python uses ** indent ** for statement grouping. --When entering a compound sentence in an interactive environment, insert a blank line at the end. --Align the indents between the lines in the block. --The print () function can specify multiple items separated by commas and delimiters. --A space is inserted between the items to be displayed. - Conditional branch ** is judged by a conditional statement that returns a True or False ** bool type . --As for numerical data, 0 is False and non-zero is True. - When using a sequence ** (list or character string) for judgment, a length other than 0 is true and a length 0 is false. --The ** comparison operators ** used in conditional statements are as follows.
There are several other things. (-> [5.7 Supplementary information about conditions](https://qiita.com/Wakii/items/34585aa75bf8c6a5b219#57-%E6%9D%A1%E4%BB%B6%E3%81%AB%E3%81% A4% E3% 81% 84% E3% 81% A6% E3% 81% AE% E8% A3% 9C% E8% B6% B3))

Comparison operator Description
a == b True if a and b are equal(true)
a != b True if a and b are not equal(true)
a < b True if a is less than b(true)
a > b True if a is greater than b(true)
a <= b True if a is greater than or equal to b(true)
a >= b True if a is less than or equal to b(true)

Next article: The contents of the Python tutorial (Chapter 4) are itemized

Recommended Posts

The contents of the Python tutorial (Chapter 5) are itemized.
The contents of the Python tutorial (Chapter 4) are itemized.
The contents of the Python tutorial (Chapter 2) are itemized.
The contents of the Python tutorial (Chapter 8) are itemized.
The contents of the Python tutorial (Chapter 1) are itemized.
The contents of the Python tutorial (Chapter 10) are itemized.
The contents of the Python tutorial (Chapter 3) are itemized.
Get the contents of git diff from python
the zen of Python
Template of python script to read the contents of the file
Not being aware of the contents of the data in python
Reproduce the execution example of Chapter 4 of Hajipata in Python
[Maya Python] Crush the contents of the script 2 ~ list Notes
Reproduce the execution example of Chapter 5 of Hajipata in Python
About the ease of Python
About the features of Python
Simulation of the contents of the wallet
The Power of Pandas: Python
About the matter that the contents of Python print are not visible in docker logs
[Maya Python] Crush the contents of the script 3 ~ List unknown Plugins
[Maya Python] Crush the contents of the script 1 ~ Camera Speed Editor
[Data science memorandum] Confirmation of the contents of DataFrame type [python]
A Python script that compares the contents of two directories
How to check if the contents of the dictionary are the same in Python by hash value
The story of Python and the story of NaN
Easy encryption of file contents (Python)
[Python] The stumbling block of import
[Python of Hikari-] Chapter 09-03 Class (inheritance)
First Python 3 ~ The beginning of repetition ~
[Python] [Table of Contents Links] Python Programming
Understand the contents of sklearn's pipeline
[Translation] scikit-learn 0.18 Tutorial Table of Contents
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
See the contents of Kumantic Segumantion
Python Math Series ⓪ Table of Contents
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Introductory table of contents for python3
About the basics list of Python basics
Learn the basics of Python ① Beginners
[python, ruby] fetch the contents of a web page with selenium-webdriver
Output the contents of ~ .xlsx in the folder to HTML with Python
[Python of Hikari-] Chapter 07-02 Exception handling (continuous execution of the program by exception handling)
Verification of the theory that "Python and Swift are quite similar"
Contents of reading VBA x Python fastest work technique Memo chapter1
[Python] A program that rotates the contents of the list to the left
I checked the contents of docker volume
Check the behavior of destructor in Python
[Python3] Understand the basics of Beautiful Soup
Pass the path of the imported python module
Check the existence of the file with python
About the virtual environment of python version 3.7
Python tutorial
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Python3] Rewrite the code object of the function
I didn't know the basics of Python
How to compare if the contents of the objects in scipy.sparse.csr_matrix are the same
The result of installing python in Anaconda
[Python] Try pydash of the Python version of lodash