In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points of case analysis of weird behavior in Java and Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Reassignment of True Evil in Python 2
> True = False > True False
Thankfully, this leads to SyntaxError in Python 3, because True, False, and None are now reserved words. It's still not nearly as evil as C++ 's prank, stealthily writing # define true false into the standard header files of colleagues' development machines.
Examples of weird behavior in Java and Python
For novice Java programmers, the semantics of = = are often confusing. Even in trivial situations, the inconsistencies of this operator can complicate the situation, even if the performance benefit is worth it.
Integer a = 100; Integer b = 100; System.out.print (a = = b); / / prints true Integer c = 200; Integer d = 200; System.out.print (c = = d); / / prints false
JVM uses the same reference for the values in the interval [- 128,127]. What's even weirder is that the same behavior occurs in Python.
> x = 256 > y = 256 > x is y True > x = 257 > y = 257 > x is y False
So far, there has been nothing particularly unexpected.
> x =-5 > y =-5 > x is y True > x =-6 > y =-6 > x is y False
It seems that the lower limit for the python interpreter to use the same example is... -5. Integers in the interval [- 5,256] have the same ID. Somehow, it got even weirder.
> x =-10 > y =-10 > > x is y False > x, y = [- 10,-10] > x is y True
It seems that the use of deconstruction assignment has changed the rules here. I'm not sure why. In fact, I asked a question on Stack Overflow to try to understand it. My guess is that repeated values in a list point to the same object to save memory.
Inverted subscript symbol in C
Inverted subscript symbols will give all developers a headache.
Int x [1] = {0xdeadbeef}; printf ("% xn", 0 [x]); / / prints deadbeef
The reason this works is that array [index] is really just a grammatical sugar for * (array + index). Because of the commutativity of addition, we can exchange arrays and indexes and get the same result.
Reciprocal operator in C
The-> operator * * appears to be a syntactic error when it is seen for the first time. When you realize that it can be compiled, it looks like an undocumented language feature. Fortunately, it is neither.
For (x = 3; x-- > 0;) {printf ("% d", x); / / prints 210}
The-> "operator" is actually two operators, which are resolved to (x -) > 0 in this context. It is well known that heavy use can lead to confusion, which is completely evil.
Sizeof operator in C
The sizeof operator is a compile-time operator, which gives it interesting properties.
Int x = 0; sizeof (x + = 1); if (x = = 0) {printf ("wtf?"); / / this will be printed}
Because the example of the sizeof operator is evaluated at compile time, (x + = 1) will not run. Another interesting thing is that research shows that printf ("wtf?") Is the most common code that is not push.
Lua, Smalltalk, MATLAB and other languages, indexing starts at 1
/ r/programminghumor has been using "indexing starts at 1" emojis for fun. Shockingly, there are a large number of programming languages that use array indexes starting at 1. A more comprehensive list can be found here.
0 in Ruby is judged to be true
... And only Ruby. *
This is true in Ruby. *
If 0 then print 'thanks, ruby' end # prints thanks, ruby
* edit: It was pointed out on reddit that this is true for Lua, Lisp, and Erlang as well.
* revision: it has been pointed out on Reddit that this is also true in Lua, Lisp and Erlang.
Trigraph, Digraphs, and Tokens in C
Trigraph, Digraph and Token in C
For historical reasons, there are substitutes for non-alphabetic symbols in C language.
If (true and true) {/ / same as if (true & & true) printf ("thanks, c");} above is all the content of this article entitled "case Analysis of weird behavior in Java and Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.