I hardly remember Python! However, I need to use it often, and I feel that I am investigating the same thing many times, so I will leave a memorandum in the future. I will add it every time I check it.
It may not be useful because it is a personal memo, but please use it if you like.
test_str = '100'
int(test_str)
print('text', end='')
# add path
path = './'
path = os.path.join(path, 'dir')
# generate path
path = ['./', 'dir']
path = os.path.join(*path_list)
If you use ʻenumerate ()`, you can get it at the time of loop without writing the addition of the counter.
python
test_list = ['test1', 'test2', 'test3']
for idx, test in enumerate(test_list):
print('{} : {}'.format(idx, test))
python
test_str = 'Hello World'
test_str.split() #Separate by space →['Hello', 'World']
test_str.split('o') #'o'Separated by →['Hell', ' W', 'rld']
python
test_str = 'Hello World'
test_list = test_str.split()
test_join = ''
test_join = test_join.join(test_list) #Between`test`Put and combine →'HelloWorld'
test_join = ' '
test_join = test_join.join(test_list) #Between`test`Put and combine →'Hello World'
python
test_str = 'Hello World'
test_str.replace('o', 'p') #'o'To'p'Convert to →'Hellp Wprld'
test_str.replace('o', 'p', 1) #only 1 time'o'To'p'Convert to →'Hellp World'
If you just want to delete it, you only need the second line, but considering that the key does not exist, it seems safer to keep it in the second line.
if 'key' in dic:
del dic['key']
If you try to delete the key inside the loop, you will get an error, so do the following:
for key in list(dic):
if ...: #Favorite conditions
del dic[key]
math
import math
from math import * ## math.No need to put on
math.sin(radian)
math.cos(radian)
math.tan(radian)
math.exp(x)
math.log(x)
math.pow(x, y)
math.sqrt(x)
math.pi
math.e
numpy
import numpy as np
#Zero matrix generation
zeros_array = np.zeros((row, column))
#Ichi matrix generation
ones_array = np.ones((row, column))
#Numeric matrix generation
value_array = np.full((row, column), value)
np.dot(A, B)
OpenCV
import cv2
img = cv2.imread(path)
cv2.imshow('img', img)
cv2.waitKey(0) #The argument is the drawing time
cv2.destroyAllWindows()
cv2.imread(path, img)
Recommended Posts