回答編集履歴

2

成形

2017/10/29 11:55

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -62,6 +62,8 @@
62
62
 
63
63
  {'a': <class 'int'>, 'b': <class 'int'>, 'return': <class 'int'>}
64
64
 
65
+ >>>
66
+
65
67
  >>> print.__annotations__
66
68
 
67
69
  Traceback (most recent call last):

1

追記

2017/10/29 11:55

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -46,6 +46,34 @@
46
46
 
47
47
 
48
48
 
49
+ **アノテーション見たり**
50
+
51
+ 見られるとは限りませんが。
52
+
53
+ ```Python
54
+
55
+ >>> def add(a: int, b: int) -> int:
56
+
57
+ ... return a + b
58
+
59
+ ...
60
+
61
+ >>> add.__annotations__
62
+
63
+ {'a': <class 'int'>, 'b': <class 'int'>, 'return': <class 'int'>}
64
+
65
+ >>> print.__annotations__
66
+
67
+ Traceback (most recent call last):
68
+
69
+ File "<stdin>", line 1, in <module>
70
+
71
+ AttributeError: 'builtin_function_or_method' object has no attribute '__annotations__'
72
+
73
+ ```
74
+
75
+
76
+
49
77
  対話環境で色々調べられるので便利です。
50
78
 
51
79
  戻り値の型などはあまり意識しなくてもよい、柔軟な言語だと思っています。