istr-python 1.1.4.post0__tar.gz → 1.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/PKG-INFO +49 -21
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/README.md +48 -20
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr/istr.py +36 -68
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr_python.egg-info/PKG-INFO +49 -21
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/pyproject.toml +1 -1
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr/__init__.py +0 -0
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/setup.cfg +0 -0
- {istr_python-1.1.4.post0 → istr_python-1.1.6}/tests/test_istr.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -362,7 +362,7 @@ istr.is_odd(5) ==> True
|
|
|
362
362
|
```
|
|
363
363
|
#### test for square
|
|
364
364
|
|
|
365
|
-
It is possible to test whether the value is a perfect
|
|
365
|
+
It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
|
|
366
366
|
|
|
367
367
|
```
|
|
368
368
|
istr(4).is_square() ==> True
|
|
@@ -373,6 +373,34 @@ It is also possible to test for square of an ordinary int:
|
|
|
373
373
|
istr.is_square(4) ==> True
|
|
374
374
|
istr.is_square(5) ==> False
|
|
375
375
|
```
|
|
376
|
+
#### test for cube
|
|
377
|
+
|
|
378
|
+
It is possible to test whether the value is a perfect cube (provided the istr can be interpreted as an int) with the `is_cube` method, e.g.
|
|
379
|
+
|
|
380
|
+
```
|
|
381
|
+
istr(27).is_cube() ==> True
|
|
382
|
+
istr(28).is_cube()) ==> False
|
|
383
|
+
```
|
|
384
|
+
It is also possible to test for cube of an ordinary int:
|
|
385
|
+
```
|
|
386
|
+
istr.is_cube(27) ==> True
|
|
387
|
+
istr.is_cube(28 ==> False
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
#### test for power of
|
|
391
|
+
|
|
392
|
+
It is possible to test whether the value is a perfect power of a given exponent (provided the istr can be interpreted as an int) with the `is_power_of` method, e.g.
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
istr(81).is_power_of(4) ==> True
|
|
396
|
+
istr(82).is_power_of(4) ==> False
|
|
397
|
+
```
|
|
398
|
+
It is also possible to test for power of of an ordinary int:
|
|
399
|
+
```
|
|
400
|
+
istr.is_power_of(81, 4) ==> True
|
|
401
|
+
istr.is_power_of(82, 4) ==> False
|
|
402
|
+
```
|
|
403
|
+
|
|
376
404
|
#### test for prime
|
|
377
405
|
|
|
378
406
|
It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
|
|
@@ -758,25 +786,25 @@ operator/function int str Example
|
|
|
758
786
|
+ x istr(20) + 3 ==> istr('23')
|
|
759
787
|
_ x istr(20) - 3 ==> istr('17')
|
|
760
788
|
* x istr(20) * 3 ==> istr('60')
|
|
761
|
-
/ x istr(20) / 3 ==> istr('6')
|
|
762
|
-
// x istr(20) // 3 ==> istr('6')
|
|
763
|
-
% x istr(20) % 3 ==> istr('2')
|
|
764
|
-
divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
|
|
765
|
-
** x istr(2) ** 3 ==> istr('8')
|
|
766
|
-
<=, <, >, >= x istr('100') > istr('2') ==> True
|
|
767
|
-
abs x abs(istr(-20)) ==> istr('20')
|
|
768
|
-
== x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
|
|
769
|
-
bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
|
|
770
|
-
@ x istr(20) @ 3 ==> istr('202020')
|
|
771
|
-
| x istr(20) | '5' ==> istr('205')
|
|
772
|
-
slicing x istr(12345)[1:3] ==> istr('23')
|
|
773
|
-
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
774
|
-
len x len(istr(' 20 ')) ==> 4
|
|
775
|
-
count x istr(100).count('0') ==> 2
|
|
776
|
-
index x istr(' 100 ').index('0') ==> 2
|
|
777
|
-
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
778
|
-
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
779
|
-
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
789
|
+
/ x istr(20) / 3 ==> istr('6')
|
|
790
|
+
// x istr(20) // 3 ==> istr('6')
|
|
791
|
+
% x istr(20) % 3 ==> istr('2')
|
|
792
|
+
divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
|
|
793
|
+
** x istr(2) ** 3 ==> istr('8')
|
|
794
|
+
<=, <, >, >= x istr('100') > istr('2') ==> True
|
|
795
|
+
abs x abs(istr(-20)) ==> istr('20')
|
|
796
|
+
== x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
|
|
797
|
+
bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
|
|
798
|
+
@ x istr(20) @ 3 ==> istr('202020')
|
|
799
|
+
| x istr(20) | '5' ==> istr('205')
|
|
800
|
+
slicing x istr(12345)[1:3] ==> istr('23')
|
|
801
|
+
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
802
|
+
len x len(istr(' 20 ')) ==> 4
|
|
803
|
+
count x istr(100).count('0') ==> 2
|
|
804
|
+
index x istr(' 100 ').index('0') ==> 2
|
|
805
|
+
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
806
|
+
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
807
|
+
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
780
808
|
istr('aAbBcC').islower() ==> False
|
|
781
809
|
istr(' abc ').strip() ==> istr('abc')
|
|
782
810
|
...
|
|
@@ -349,7 +349,7 @@ istr.is_odd(5) ==> True
|
|
|
349
349
|
```
|
|
350
350
|
#### test for square
|
|
351
351
|
|
|
352
|
-
It is possible to test whether the value is a perfect
|
|
352
|
+
It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
|
|
353
353
|
|
|
354
354
|
```
|
|
355
355
|
istr(4).is_square() ==> True
|
|
@@ -360,6 +360,34 @@ It is also possible to test for square of an ordinary int:
|
|
|
360
360
|
istr.is_square(4) ==> True
|
|
361
361
|
istr.is_square(5) ==> False
|
|
362
362
|
```
|
|
363
|
+
#### test for cube
|
|
364
|
+
|
|
365
|
+
It is possible to test whether the value is a perfect cube (provided the istr can be interpreted as an int) with the `is_cube` method, e.g.
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
istr(27).is_cube() ==> True
|
|
369
|
+
istr(28).is_cube()) ==> False
|
|
370
|
+
```
|
|
371
|
+
It is also possible to test for cube of an ordinary int:
|
|
372
|
+
```
|
|
373
|
+
istr.is_cube(27) ==> True
|
|
374
|
+
istr.is_cube(28 ==> False
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### test for power of
|
|
378
|
+
|
|
379
|
+
It is possible to test whether the value is a perfect power of a given exponent (provided the istr can be interpreted as an int) with the `is_power_of` method, e.g.
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
istr(81).is_power_of(4) ==> True
|
|
383
|
+
istr(82).is_power_of(4) ==> False
|
|
384
|
+
```
|
|
385
|
+
It is also possible to test for power of of an ordinary int:
|
|
386
|
+
```
|
|
387
|
+
istr.is_power_of(81, 4) ==> True
|
|
388
|
+
istr.is_power_of(82, 4) ==> False
|
|
389
|
+
```
|
|
390
|
+
|
|
363
391
|
#### test for prime
|
|
364
392
|
|
|
365
393
|
It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
|
|
@@ -745,25 +773,25 @@ operator/function int str Example
|
|
|
745
773
|
+ x istr(20) + 3 ==> istr('23')
|
|
746
774
|
_ x istr(20) - 3 ==> istr('17')
|
|
747
775
|
* x istr(20) * 3 ==> istr('60')
|
|
748
|
-
/ x istr(20) / 3 ==> istr('6')
|
|
749
|
-
// x istr(20) // 3 ==> istr('6')
|
|
750
|
-
% x istr(20) % 3 ==> istr('2')
|
|
751
|
-
divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
|
|
752
|
-
** x istr(2) ** 3 ==> istr('8')
|
|
753
|
-
<=, <, >, >= x istr('100') > istr('2') ==> True
|
|
754
|
-
abs x abs(istr(-20)) ==> istr('20')
|
|
755
|
-
== x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
|
|
756
|
-
bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
|
|
757
|
-
@ x istr(20) @ 3 ==> istr('202020')
|
|
758
|
-
| x istr(20) | '5' ==> istr('205')
|
|
759
|
-
slicing x istr(12345)[1:3] ==> istr('23')
|
|
760
|
-
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
761
|
-
len x len(istr(' 20 ')) ==> 4
|
|
762
|
-
count x istr(100).count('0') ==> 2
|
|
763
|
-
index x istr(' 100 ').index('0') ==> 2
|
|
764
|
-
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
765
|
-
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
766
|
-
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
776
|
+
/ x istr(20) / 3 ==> istr('6')
|
|
777
|
+
// x istr(20) // 3 ==> istr('6')
|
|
778
|
+
% x istr(20) % 3 ==> istr('2')
|
|
779
|
+
divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
|
|
780
|
+
** x istr(2) ** 3 ==> istr('8')
|
|
781
|
+
<=, <, >, >= x istr('100') > istr('2') ==> True
|
|
782
|
+
abs x abs(istr(-20)) ==> istr('20')
|
|
783
|
+
== x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
|
|
784
|
+
bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
|
|
785
|
+
@ x istr(20) @ 3 ==> istr('202020')
|
|
786
|
+
| x istr(20) | '5' ==> istr('205')
|
|
787
|
+
slicing x istr(12345)[1:3] ==> istr('23')
|
|
788
|
+
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
789
|
+
len x len(istr(' 20 ')) ==> 4
|
|
790
|
+
count x istr(100).count('0') ==> 2
|
|
791
|
+
index x istr(' 100 ').index('0') ==> 2
|
|
792
|
+
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
793
|
+
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
794
|
+
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
767
795
|
istr('aAbBcC').islower() ==> False
|
|
768
796
|
istr(' abc ').strip() ==> istr('abc')
|
|
769
797
|
...
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
8
|
+
__version__ = "1.1.6"
|
|
9
9
|
import functools
|
|
10
|
-
import math
|
|
11
10
|
import itertools
|
|
12
11
|
import types
|
|
13
12
|
import sys
|
|
@@ -16,7 +15,7 @@ import inspect
|
|
|
16
15
|
"""
|
|
17
16
|
Note: the changelog is now in changelog.md
|
|
18
17
|
|
|
19
|
-
You can view the changelog on www.salabim.org/istr/changelog
|
|
18
|
+
You can view the changelog on www.salabim.org/istr/changelog
|
|
20
19
|
|
|
21
20
|
The readme can be viewed on www.salabim.org/istr/
|
|
22
21
|
"""
|
|
@@ -203,7 +202,8 @@ class istr(str):
|
|
|
203
202
|
it is possible to give more than one parameter, in which case a tuple
|
|
204
203
|
of the istrs of the parameters will be returned, which can be handy
|
|
205
204
|
to multiple assign, e.g.
|
|
206
|
-
a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
|
|
205
|
+
a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
|
|
206
|
+
"""
|
|
207
207
|
|
|
208
208
|
__slots__ = ("_as_int", "_as_repr")
|
|
209
209
|
|
|
@@ -346,57 +346,30 @@ class istr(str):
|
|
|
346
346
|
return int(self._as_int)
|
|
347
347
|
|
|
348
348
|
def is_even(self):
|
|
349
|
-
|
|
350
|
-
if not self.is_int():
|
|
351
|
-
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
352
|
-
n = self._as_int
|
|
353
|
-
else:
|
|
354
|
-
n = int(self)
|
|
355
|
-
|
|
356
|
-
return n % 2 == 0
|
|
349
|
+
return istr.is_divisible_by(self,2)
|
|
357
350
|
|
|
358
351
|
def is_odd(self):
|
|
359
|
-
|
|
360
|
-
if not self.is_int():
|
|
361
|
-
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
362
|
-
n = self._as_int
|
|
363
|
-
else:
|
|
364
|
-
n = int(self)
|
|
352
|
+
return not istr.is_divisible_by(self,2)
|
|
365
353
|
|
|
366
|
-
|
|
354
|
+
def is_divisible_by(self, divisor):
|
|
355
|
+
return istr.interpret_as_int(self) % int(divisor) == 0
|
|
367
356
|
|
|
368
357
|
def is_square(self):
|
|
369
|
-
return istr.
|
|
358
|
+
return istr.is_power_of(self, 2)
|
|
370
359
|
|
|
371
360
|
def is_cube(self):
|
|
372
|
-
return istr.
|
|
361
|
+
return istr.is_power_of(self, 3)
|
|
373
362
|
|
|
374
|
-
def is_power_of(self,
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
382
|
-
n = self._as_int
|
|
383
|
-
else:
|
|
384
|
-
n = int(self)
|
|
385
|
-
if power_of < 1:
|
|
386
|
-
raise ValueError(f"power_of must be >=1; not {power_of}")
|
|
387
|
-
if not isinstance(power_of, int):
|
|
388
|
-
raise TypeError(f"power_of must be int; not {type(power_of)}")
|
|
389
|
-
|
|
390
|
-
return n >= 0 and self == round(n ** (1 / power_of)) ** power_of
|
|
363
|
+
def is_power_of(self, exponent):
|
|
364
|
+
n = istr.interpret_as_int(self)
|
|
365
|
+
if exponent < 1:
|
|
366
|
+
raise ValueError(f"exponent must be >=1; not {exponent}")
|
|
367
|
+
if not isinstance(exponent, int):
|
|
368
|
+
raise TypeError(f"exponent must be int; not {type(exponent)}")
|
|
369
|
+
return n >= 0 and self == round(n ** (1 / exponent)) ** exponent
|
|
391
370
|
|
|
392
371
|
def is_prime(self):
|
|
393
|
-
|
|
394
|
-
if not self.is_int():
|
|
395
|
-
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
396
|
-
n = self._as_int
|
|
397
|
-
else:
|
|
398
|
-
n = int(self)
|
|
399
|
-
|
|
372
|
+
n = istr.interpret_as_int(self)
|
|
400
373
|
if n < 2:
|
|
401
374
|
return False
|
|
402
375
|
if n == 2:
|
|
@@ -430,6 +403,19 @@ class istr(str):
|
|
|
430
403
|
raise ValueError(f"incorrect number of variables {len(letters)}; should be {len(self)}")
|
|
431
404
|
namespace.update(lookup)
|
|
432
405
|
|
|
406
|
+
@classmethod
|
|
407
|
+
def compose(cls, letters, namespace=None):
|
|
408
|
+
"""
|
|
409
|
+
compose an istr from individual letter variables
|
|
410
|
+
"""
|
|
411
|
+
if namespace is None:
|
|
412
|
+
namespace = inspect.currentframe().f_back.f_globals
|
|
413
|
+
for letter in letters:
|
|
414
|
+
if letter not in namespace:
|
|
415
|
+
raise ValueError(f"variable {letter} not defined")
|
|
416
|
+
|
|
417
|
+
return istr("").join(istr(namespace[letter]) for letter in letters)
|
|
418
|
+
|
|
433
419
|
def __or__(self, other):
|
|
434
420
|
try:
|
|
435
421
|
return self.__class__(str(self).__add__(other))
|
|
@@ -463,14 +449,14 @@ class istr(str):
|
|
|
463
449
|
def reversed(self):
|
|
464
450
|
return self[::-1]
|
|
465
451
|
|
|
466
|
-
def
|
|
452
|
+
def interpret_as_int(self):
|
|
467
453
|
if isinstance(self, istr):
|
|
468
454
|
if not self.is_int():
|
|
469
455
|
raise TypeError(f"not interpretable as int: {self._frepr(self)}")
|
|
470
456
|
n = self._as_int
|
|
471
457
|
else:
|
|
472
458
|
n = int(self)
|
|
473
|
-
return n
|
|
459
|
+
return n
|
|
474
460
|
|
|
475
461
|
def _str_method(self, name, *args, **kwargs):
|
|
476
462
|
return self.__class__(getattr(super(), name)(*args, **kwargs))
|
|
@@ -576,7 +562,7 @@ class istr(str):
|
|
|
576
562
|
if no args, 0-9 will be used
|
|
577
563
|
|
|
578
564
|
all given args will be used
|
|
579
|
-
each arg has to be either null string, <digit>, <digit>-<digit
|
|
565
|
+
each arg has to be either null string, <digit>, <digit>-<digit>, <digit>- or -<digit>
|
|
580
566
|
|
|
581
567
|
the digits may be '0' through '9' and 'A' through 'Z' (not case sensitive)
|
|
582
568
|
The returned value will always be in uppercase (if applicable).
|
|
@@ -637,29 +623,13 @@ class istr(str):
|
|
|
637
623
|
cls._digits_cache[key] = result
|
|
638
624
|
return result
|
|
639
625
|
|
|
640
|
-
@classmethod
|
|
641
|
-
def compose(cls, letters, namespace=None):
|
|
642
|
-
"""
|
|
643
|
-
compose an istr from individual letter variables
|
|
644
|
-
"""
|
|
645
|
-
if namespace is None:
|
|
646
|
-
namespace = inspect.currentframe().f_back.f_globals
|
|
647
|
-
for letter in letters:
|
|
648
|
-
if letter not in namespace:
|
|
649
|
-
raise ValueError(f"variable {letter} not defined")
|
|
650
|
-
|
|
651
|
-
return istr("").join(istr(namespace[letter]) for letter in letters)
|
|
652
|
-
|
|
653
626
|
|
|
654
627
|
istr.type = type(istr(0))
|
|
655
628
|
|
|
656
629
|
|
|
657
|
-
def main(): ...
|
|
658
|
-
|
|
659
|
-
|
|
660
630
|
class istrModule(types.ModuleType):
|
|
661
631
|
def __call__(self, *args, **kwargs):
|
|
662
|
-
return istr
|
|
632
|
+
return istr(*args, **kwargs)
|
|
663
633
|
|
|
664
634
|
def __setattr__(self, item, value):
|
|
665
635
|
setattr(istr, item, value)
|
|
@@ -668,7 +638,5 @@ class istrModule(types.ModuleType):
|
|
|
668
638
|
return getattr(istr, item)
|
|
669
639
|
|
|
670
640
|
|
|
671
|
-
if __name__
|
|
672
|
-
main()
|
|
673
|
-
else:
|
|
641
|
+
if __name__ != "__main__":
|
|
674
642
|
sys.modules["istr"].__class__ = istrModule
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -362,7 +362,7 @@ istr.is_odd(5) ==> True
|
|
|
362
362
|
```
|
|
363
363
|
#### test for square
|
|
364
364
|
|
|
365
|
-
It is possible to test whether the value is a perfect
|
|
365
|
+
It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
|
|
366
366
|
|
|
367
367
|
```
|
|
368
368
|
istr(4).is_square() ==> True
|
|
@@ -373,6 +373,34 @@ It is also possible to test for square of an ordinary int:
|
|
|
373
373
|
istr.is_square(4) ==> True
|
|
374
374
|
istr.is_square(5) ==> False
|
|
375
375
|
```
|
|
376
|
+
#### test for cube
|
|
377
|
+
|
|
378
|
+
It is possible to test whether the value is a perfect cube (provided the istr can be interpreted as an int) with the `is_cube` method, e.g.
|
|
379
|
+
|
|
380
|
+
```
|
|
381
|
+
istr(27).is_cube() ==> True
|
|
382
|
+
istr(28).is_cube()) ==> False
|
|
383
|
+
```
|
|
384
|
+
It is also possible to test for cube of an ordinary int:
|
|
385
|
+
```
|
|
386
|
+
istr.is_cube(27) ==> True
|
|
387
|
+
istr.is_cube(28 ==> False
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
#### test for power of
|
|
391
|
+
|
|
392
|
+
It is possible to test whether the value is a perfect power of a given exponent (provided the istr can be interpreted as an int) with the `is_power_of` method, e.g.
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
istr(81).is_power_of(4) ==> True
|
|
396
|
+
istr(82).is_power_of(4) ==> False
|
|
397
|
+
```
|
|
398
|
+
It is also possible to test for power of of an ordinary int:
|
|
399
|
+
```
|
|
400
|
+
istr.is_power_of(81, 4) ==> True
|
|
401
|
+
istr.is_power_of(82, 4) ==> False
|
|
402
|
+
```
|
|
403
|
+
|
|
376
404
|
#### test for prime
|
|
377
405
|
|
|
378
406
|
It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
|
|
@@ -758,25 +786,25 @@ operator/function int str Example
|
|
|
758
786
|
+ x istr(20) + 3 ==> istr('23')
|
|
759
787
|
_ x istr(20) - 3 ==> istr('17')
|
|
760
788
|
* x istr(20) * 3 ==> istr('60')
|
|
761
|
-
/ x istr(20) / 3 ==> istr('6')
|
|
762
|
-
// x istr(20) // 3 ==> istr('6')
|
|
763
|
-
% x istr(20) % 3 ==> istr('2')
|
|
764
|
-
divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
|
|
765
|
-
** x istr(2) ** 3 ==> istr('8')
|
|
766
|
-
<=, <, >, >= x istr('100') > istr('2') ==> True
|
|
767
|
-
abs x abs(istr(-20)) ==> istr('20')
|
|
768
|
-
== x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
|
|
769
|
-
bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
|
|
770
|
-
@ x istr(20) @ 3 ==> istr('202020')
|
|
771
|
-
| x istr(20) | '5' ==> istr('205')
|
|
772
|
-
slicing x istr(12345)[1:3] ==> istr('23')
|
|
773
|
-
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
774
|
-
len x len(istr(' 20 ')) ==> 4
|
|
775
|
-
count x istr(100).count('0') ==> 2
|
|
776
|
-
index x istr(' 100 ').index('0') ==> 2
|
|
777
|
-
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
778
|
-
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
779
|
-
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
789
|
+
/ x istr(20) / 3 ==> istr('6')
|
|
790
|
+
// x istr(20) // 3 ==> istr('6')
|
|
791
|
+
% x istr(20) % 3 ==> istr('2')
|
|
792
|
+
divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
|
|
793
|
+
** x istr(2) ** 3 ==> istr('8')
|
|
794
|
+
<=, <, >, >= x istr('100') > istr('2') ==> True
|
|
795
|
+
abs x abs(istr(-20)) ==> istr('20')
|
|
796
|
+
== x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
|
|
797
|
+
bool x x *) bool(istr(' 0 ')) ==> False | istr('') ==> False
|
|
798
|
+
@ x istr(20) @ 3 ==> istr('202020')
|
|
799
|
+
| x istr(20) | '5' ==> istr('205')
|
|
800
|
+
slicing x istr(12345)[1:3] ==> istr('23')
|
|
801
|
+
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
802
|
+
len x len(istr(' 20 ')) ==> 4
|
|
803
|
+
count x istr(100).count('0') ==> 2
|
|
804
|
+
index x istr(' 100 ').index('0') ==> 2
|
|
805
|
+
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
806
|
+
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
807
|
+
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
780
808
|
istr('aAbBcC').islower() ==> False
|
|
781
809
|
istr(' abc ').strip() ==> istr('abc')
|
|
782
810
|
...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|