Define a primitive data type: Difference between revisions

Content added Content deleted
(omits)
(Add Python)
Line 627: Line 627:
$t = 'xyzzy';
$t = 'xyzzy';
# dies, too small. string is 0 interpreted numerically</lang>
# dies, too small. string is 0 interpreted numerically</lang>

=={{header|Python}}==
This doesn't really apply as Python names don't have a type, but something can be done:
<lang python>>>> class num(int):
def __init__(self, b):
if 1 <= b <= 10:
return int.__init__(self+0)
else:
raise ValueError,"Value %s should be >=0 and <= 10" % b

>>> x = num(3)
>>> x = num(11)

Traceback (most recent call last):
File "<pyshell#394>", line 1, in <module>
x = num(11)
File "<pyshell#392>", line 6, in __init__
raise ValueError,"Value %s should be >=0 and <= 10" % b
ValueError: Value 11 should be >=0 and <= 10
>>> x
3
>>> type(x)
<class '__main__.num'>
>>> </lang>



=={{header|Tcl}}==
=={{header|Tcl}}==