Programming Books

Main Menu

  • Home
  • Phyton programming
  • Java programming
  • Php programming
  • C++ programming
  • Additional Topics
    • Programming industry
    • Privacy Policy
    • Terms and Conditions

Programming Books

Header Banner

Programming Books

  • Home
  • Phyton programming
  • Java programming
  • Php programming
  • C++ programming
  • Additional Topics
    • Programming industry
    • Privacy Policy
    • Terms and Conditions
Java programming
Home›Java programming›Python 3.10 runs switch equivalent, adds more help if something goes wrong • DEVCLASS

Python 3.10 runs switch equivalent, adds more help if something goes wrong • DEVCLASS

By Brandy J. Richardson
October 5, 2021
0
0


Version 3.10 of the popular Python programming language has been released as expected, and while the update doesn’t bring a ton of changes, the new syntax and typing features are cool enough to make it worth it.

The great feature of the version must definitely be the correspondence of the structural patterns. The addition is intended to provide Python developers with an easier way to extract information from complex data types and apply actions based on the data shapes (hence the structural part of the name). Structural model matching matches dictionary structures with binding and can be likened to a switch statement in C and Java, so developers don’t have to rely on if/else/elif blocks to handle more expression values.

The functionality is implemented via a meet statement which “takes an expression and compares its value to successive models given in the form of one or more blocks of cases”. A basic example of (one of) associated PEP (s) looks like this:

#point is an (x, y) tuple

match point:
     case (0, 0):
          print("Origin")
     case (0, y):
          print(f"Y={y}")
     case (x, 0):
          print(f"X={x}")
     case (x, y):
          print(f"X={x}, Y={y}")
     case _:
          raise ValueError("Not a point")

The underscore (_) in the latter case of the example is a wildcard, which already shows one of the peculiarities of the improvement that led to at least one of the many discussions during the design phase of the improvement. It must be said that the use is not entirely intuitive, as shown by the fact that you can use the morse operator in the match statement, but not in the case statement. However, the Python team did their best to explain the new addition and provided an in-depth tutorial to help developers familiarize themselves with the new syntax.

Apart from that, Python 3.10 includes a new type of union operator that allows developers to write X|Y in the place of Union [X,Y] say that type X or Y would be an option in type indication scenarios and a TypeAlias value to declare type aliases, which makes them easier to distinguish from normal assignments. There is also the addition of parameter specific variables in the input module, but these could be more interesting for tool builders.

With a bit of interpreter work, Python code should become a bit easier to debug from this version on, as the error messages will finally point out where the error actually is instead of leading you to the next. next line. Another improvement in this area is the introduction of more useful error messages.

For example, the Python team added more context and extra guidance on syntax errors, so developers can find unclosed brackets, missing colons before blocks and in dictionary literals faster, and the missing commas in the literals of the collection. PyErr_Display() Also learned how to use object or function information to come up with suggestions for similar attributes or variable names when attribute or name errors are found, which should be helpful if you tend to misspell things or if you have to work a lot with unknown code.

A full list of changes, which also include optimization in various constructors to speed up the code, can be found in the Python documentation. It also comes with a list of mid-size deprecations, the most notable being a number of threading and syntax methods that allow you to track numeric literals by keywords and, if not, for, if, in, is and or that will soon result in an error. Users should also be aware that Python 3.10 requires OpenSSL 1.1.1 or newer to work, although hopefully most have already passed.

With Python 3.10 officially available, it will be interesting to see if the new features can inspire enough articles and online discussions to move the language up the TIOBE programming community index. The September edition saw Python only need 0.16% to overtake C in popularity – and given the way the ranking is constructed, it should be quick to capture such development.


Related posts:

  1. betterCode () Rust: longer reduction for early birds also in combination with betterCode () Go
  2. Go from zero to hero as a professional Java programmer for $ 30
  3. The Great Learning Academy has seen its user base increase by 5 times
  4. Senior Java Developer – IT-Online

Archives

  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • January 2021
  • December 2019
  • November 2019
  • October 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2017

Categories

  • C++ programming
  • Java programming
  • Php programming
  • Phyton programming
  • Programming industry

Recent Posts

  • 12-bit dual-channel PCIe card samples at 2x 3.2 Gsample/s
  • Woster: Need work for those stifled by student loans – Mitchell Republic
  • How to Become a Cloud Engineer
  • [Unveil]Emerging indie band SURL wants to bring rock back to the masses
  • Ansible vs. Puppet | Compare DevOps tools
  • Privacy Policy
  • Terms and Conditions