Previous article: The contents of the Python tutorial (Chapter 2) are itemized
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.
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/
--Python3 Engineer Certification Basic Exam Score ―― 6/40 questions (15.0%) ☆☆☆ ★★ (importance: medium) --Theme --Comment --Variables --Numeric types and sequences (strings, lists) --Comparison operator
--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).
――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 |
--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.
-** 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.
--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