ããã«ã¡ã¯ãPyQãã¼ã ã®kamekoã§ãã
2019å¹´10æ14æ¥ã«Python3.8.0ããªãªã¼ã¹ããã¾ããã
ããã«ã¨ããªããPyQã¯ã¨ã¹ãå®è¡ç°å¢ã®Pythonã®ãã¼ã¸ã§ã³ãPython3.8.0ã«ãã¼ã¸ã§ã³ã¢ãããã¾ããã
PyQã§ã¯ãã客æ§ãææ°ã®Pythonç°å¢ã§å¦ç¿ãã§ããããã«Pythonãã©ã¤ãã©ãªã¼ã®ã¢ãããã¼ããè¡ã£ã¦ãã¾ãã
ãããã¦Python3.8対å¿ã®åé¡ããªãªã¼ã¹ãã¾ããã追å ããåé¡ã¨Python3.8ã§è¿½å ãããæ©è½ã®ç¹å¾´ãç´¹ä»ãã¾ãã
- Python3.8ç¨ã®åé¡ã¨è§£èª¬ã追å
- Python3.8対å¿ãã¦ããªãã¯ã¨ã¹ã
- æ´æ°ãããã¯ã¨ã¹ã
Python3.8ç¨ã®åé¡ã¨è§£èª¬ã追å
Python3.8ã§è¿½å ãããæ©è½ãããã¤ãç´¹ä»ãã¾ãã
Positional-only parameters
ä½ç½®å¼æ°ãå¼·å¶ããæ©è½ã追å ããã¾ããã
é¢æ°ã®å¼æ°ã®ãªã¹ãã« /
ããã㨠/
ããåã«ããå¼æ°ã¯ãã¹ã¦ ä½ç½®å¼æ° ã¨ãã¦ãã使ããªãæ©è½ã§ãã
以ä¸ã®ãããªå°å½¢ã®é¢ç©ãæ±ããé¢æ° calc_trapezoid_area
ãä½ãå ´åãèãã¦ã¿ã¾ãã
def calc_trapezoid_area(top, bottom, height): return (top + bottom) / 2 * height
å°å½¢ã®é¢ç©ã®æ±ãæ¹ã¯ããä¸åºããä¸åºãããé«ããã2ãã¨ããå
¬å¼ãæåã§ãã
é¢æ°ä½æè
ãé¢æ°ã使ãã¨ãã«å¿
ãåããä¸åºãä¸åºãé«ãã®é çªã§å¼æ°ãæå®ãã¦ã»ããã¨èãã¦ã
Python3.7ã¾ã§ã¯ãã¼ã¯ã¼ãæå®ãå¯è½ã§ããã
å©ç¨è
ã®æ°æã¡ã²ã¨ã¤ã§æå®é ãå¤æ´ã§ãã¾ããã
calc_trapezoid_area(height=3, top=2, bottom=4)
ããããPython3.8ãã㯠/
ãæ¸ããã¨ã§ãä½ç½®å¼æ°ãå¼·å¶ã§ãããããªãã¾ããã
def calc_trapezoid_area(top, bottom, height, /): return (top + bottom) / 2 * height
ãã¼ã¯ã¼ãå¼æ°ã®å½¢ã§æå®ãã㨠TypeError
ã«ãªãã¾ãã
>>> calc_trapezoid_area(height=3, top=2, bottom=4) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: calc_trapezoid_area() got some positional-only arguments passed as keyword arguments: 'top, bottom, height'
å¿ ã以ä¸ã®ããã«ä½ç½®å¼æ°ã§æå®ãã¾ãã
>>> calc_trapezoid_area(2, 4, 3) 9.0
ãã®æ©è½ãè¨è¿°ããªããå¦ç¿ã§ããåé¡ãä»®å¼æ°ã®ä½¿ãæ¹ãå¦ã¼ã ã«è¿½å ãã¾ããã
解説ã追å ããå ´æ
ä»ã«ãPython3.8ã«è¿½å ãããæ©è½ã§ä¾¿å©ãªãã®ãããã¾ãã
æ¥æãæååã«å¤æããæ¹æ³ãå¦ã¼ã 1åç®ã§ç´¹ä»ãã¦ãã f-string
ã«è¿½å ãããæ©è½ã§ãã
ããã¾ã§ã¯ãå¤æ°ã®å¤ãéçºä¸ã«è¡¨ç¤ºããå ´åã print("x=", x)
ãªã©ã¨æ¸ãã¦ãã¾ããã
Python3.8ããã¯ã f'{x=}'
ã¨æ¸ãã ã㧠x=3
㨠x=
ä»ãã§è¡¨ç¤ºãããããã«ãªãã¾ããã
>>> x = 10 >>> print("x =", x) # Python3.5ã¾ã§ x = 10 >>> print(f'x = {x}') # Python3.7ã¾ã§ x = 10 >>> print(f'{x = }') # Python3.8ãã x = 10
ä»ã«ã以ä¸ã®ã¯ã¨ã¹ãã«Python3.8ã®æ°æ©è½ã«é¢ãã解説ã追å ãã¾ããããã²ããä¸èªãã ããã
- è«çæ¼ç®ã®å®è¡é åºï¼3ã¤ä»¥ä¸æ¡ä»¶å¼ãããå ´åï¼ 3åç®
- æååã®ä¸»ãªã¡ã½ãã 4åç®
- foræãæ¸ãã¦ã¿ãã 4åç®
- å ¥åã¨åºå 1åç®
- JSONã¨pickleã®ä½¿ãæ¹ 1åç®
- ä»®å¼æ°ã®ä½¿ãæ¹ãå¦ã¼ã 3åç®
Python3.8対å¿ãã¦ããªãã¯ã¨ã¹ã
以ä¸ã®ã¯ã¨ã¹ãã¯å©ç¨ã©ã¤ãã©ãªã¼ãPython3.8ã«æªå¯¾å¿ã®é¢ä¿ã§ãPython3.7ãå©ç¨ãã¦ãã¾ãã
- ã¹ã¯ã¬ã¤ãã³ã° ãã¼ã
- æ©æ¢°å¦ç¿Webã¢ããªã®ä½æ ãã¼ã
æ´æ°ãããã¯ã¨ã¹ã
ä»åã®æ´æ°ã§ã¯æ¢åã®ã¯ã¨ã¹ãã®ä¿®æ£ãè¡ãã¾ããã
詳ããã¯ã æ´æ°å±¥æ´2019-12-18 ãã覧ãã ããã