I am new to python programming, beauty of python is Everything an Object but why not keywords as Objects?
>>> type(for)
File "<stdin>", line 1
type(for)
^
SyntaxError: invalid syntax
Actually, operators are objects; Have a look at the operator module. You cannot get the operator objects with their usual name (since that would significantly complicate Python's grammar, and be confusing), but this works:
>>> import operator
>>> type(operator.add)
<type 'builtin_function_or_method'>
Flow control keywords such as if and for are not objects because there is no semantic - what would you do with a hypothetical for object? Note that there are functions that can replace a for loop, namely filter, map, reduce, and a variety of functions in itertools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With