fundemental.py
#Type confirmation
type()
#When using a formula, put spaces before and after the operator.
1 + 1
#This whitespace is also recommended by the Python coding convention PEP8.
#On the other hand, as a division operator that returns the quotient (integer part),//Symbols are available./Repeat the symbol twice, without any gaps. Division that returns the quotient as the calculation result is rounded down.(floor division)Is called.
##When using a cumulative assignment statement
count = 0
count += 1
count
##Format syntax
name1 = 'Chainer'
name2 = 'tutorial'
'{} {}welcome to'.format(name1, name2)
#Composite data type
list(list)
Tuple(tuple)
dictionary(dictionary)
#list
#Slice, an operation that retrieves multiple elements from a list at once(slice)
#There is an addition of the value to the list. Append for list type()Is defined, which allows you to add a new value to the end of the list.
array.append(2.5)
#Tuple
#Feature
##Tuple(tuple)Is a type that combines multiple elements like a list, but unlike a list, it has the property that the elements inside cannot be changed after it is defined.
#Dictionary type(Dict type)
##Associative array. Consists of keys and elements.
#Sometimes you want to find out what keys exist in a dictionary defined by someone else. There are several useful methods in the dictionary that you can use in such cases.
keys():Get a list of keys. dict_Returns a type similar in nature to the list called keys
values():Get a list of values. dict_Returns a type similar in nature to the list values
items():Of each element(key, value)Get a list of tuples. dict_Returns a type similar in nature to the list items
#Control syntax
##Enumerate that can be used in For statements()function
If you specify the list as an iterable object, you cannot get the element number, but in some situations you may want to use the element number. In such cases, enumerate()Use the built-in function called. If you pass an iterable object to it,(Element number,element)It is an iterable object that returns the tuples one by one.
#function
#Function double()Definition of
def double(x):
print(2 * x)
#When using multiple arguments
#Function definition
def add(a, b):
print(a + b)
#About global variables and scope
a = 1
def change():
global a #Declaration that a is a global variable
a = 2 #Assignment to a global variable
#Function execution
change()
#Check the result<-The value of a has been overwritten
a
#As you can see from the above example, change the line global a()If you add it before using the variable a in the function, the assignment to the variable a will also be made to the global variable a defined outside the function after that line.
#About Class and inheritance
See below for the easiest to understand
"https://tutorials.chainer.org/ja/src/02_Basics_of_Python_ja.html#%E3%82%AF%E3%83%A9%E3%82%B9"
useful.py
for i in range(3):
print('{}Mr.'.format(names[i]))
#zip()function
names = ['Python', 'Chainer']
versions = ['3.7', '5.3.0']
suffixes = ['!!', '!!', '?']
for name, version, suffix in zip(names, versions, suffixes):
print('{} {} {}'.format(name, version, suffix))
#Because it reflects the number of columns with the shortest length, the suffix'?'Is not used.
#How to write a while statement that you haven't used much (while is a way to continue infinitely, write an if statement in it, and end it with break.)
count = 0
while True:
print(count)
count += 1
if count == 3:
break
#How to loop using not in a While statement.
count = 0
while not count == 3:
print(count)
count += 1
I studied five or six years ago, but compared to the dawn of the past, the content is much more organized and easy to understand. This is good. Especially the description of the class. Cusso is easy to understand. Although it has nothing to do with what I learned this time, there was a moment in my mind where logical thinking and emotional thinking, which had been the number one task so far, were in harmony.
Recommended Posts