+ 1
Oddities in Python
How do you explain these anomalies... https://code.sololearn.com/cswL7cDCh5Ux/?ref=app
25 odpowiedzi
+ 2
Sanjay Kamath if some source claims that "b=(4) defines a tuple const" in Python then that source needs correction.
Would you elaborate on your question of portability? I would expect Python code to be portable from platform to platform, as long as it is within the same version of the language. I am not a Python expert, but I believe the syntax for tuples has not changed amongst Python versions.
+ 3
well, it seems that for that google calculator ^ is used as exponentation operator (in python this is **)... and anything raised to power of 0 will result to 1 ;)
you couldn't assume that all operators works same everywhere ^^
+ 2
^ is binary xor operator
0^0 result to 0 (all numbers)
then you print this result as string (str(ee))...
+ 2
visph In Asia ^^
In the United States šŗšø it's šš
0=1 š¤£š¤£š¤£
+ 2
by 'everywhere' I don't think to geographic place, but in any language and/or application...
all around the world:
anything raised to power of 0 will result to 1 (general mathematics are same everywhere)
anything xor 0 will result to anything (binary mathematics are same everywhere)
what could change is the symbol(s) used to do these operations...
+ 2
???
if this is really supposed to be a python parser, then there's a bug...
or you've entered 0**0, it show result as 0^0 (exponentiation in both cases): look at the result field... it show 0^0= 1, while the input field show 0**0...
+ 2
Brian thanks! I didn't noticed this change made to the code, so I didn't noticed this error ;)
+ 2
empty_tuple = ()
one_item_tuple = ('item',)
two_items_tuple = ('item1','item2')
two_items_tuple_bis = ('item1','item2',)
+ 1
(and you could concatenate tuples as you concatenate lists)
+ 1
visph see the doc fileš
https://drive.google.com/file/d/186yspN1zs59JhJOxspqE-SfkQxj7N51y/view
+ 1
try to put 0^0 in input field in python mode, it should result as 0 (don't know wich expression will be shown in result field)
+ 1
-1 and (-1) is the same value...
+ 1
Sanjay Kamath in program var1.0 I am guessing that you intended to create a single-value tuple by using af=(-1) and expected to find a mismatch between the tuple and the single integer -1. And you would be right. Only the syntax is wrong. The correct syntax to make af into a tuple would be af=(-1,).
+ 1
I have already explained how tuples works in the first answer of this thread ^^
+ 1
notice that only empty tuple doesn't have comma inside it ^^
0
there's no anomalies here, only expected output ^^
what are you expected?
what are you calling 'anomalies'?
printing list output square brackets notation
adding lists result to lists concatenation
parenthesis, unless having at least one comma are mathematical parenthesis, so number inside parenthesis is just number.
printing string doesn't default output quotes to wrap text (to do so you must use repr instead of str, or be in the python command line and just type your variable, without using print function), so number to string output number as number...
0
(parenthesis with at least one comma are tuples -- imutable lists -- so output is done enclosed in parenthesis)
0
Instead of:
da=0**0
print (str(ee))
Try:
da=0**0
print (str(da))
(print the correct variable)