Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the features in Python3.6

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what are the features in Python3.6", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what are the features in Python3.6" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.

More readable literal values of numbers

Python code is extremely readable and is called executable pseudocode. However, it is constantly improving, such as the more readable literal syntax of numbers, which makes it easier for programmers to read and understand numbers in a "for humans" way. You can now underline numbers and group them in the way you like. This is very convenient for binary or hexadecimal numbers or large numbers:

> six_figures = 100000

> six_figures

100000

> a = 100000000

> > a

10000

> error = 0xbad_c0ffee

> error

50159747054

> flags = 0b_0111_0101_0001_0101

> flags

29973

Keep in mind that this change is just a grammatical change, a way to represent numeric text in different ways in source code. There is no change when the virtual machine is compiled into bytecode, and you can learn more about it in PEP515.

A new method of string formatting

There are two common ways to format strings. The first is to use the "%" operator and the second is to use the format function.

"%" operator

> s = "s is d"% ('two', 2)

> > s

'two is 2'

Format function

> s = "{fruit} is {color}" .format (fruit='apple', color='red')

> > s

'apple is red'

Obviously, the format function is more readable than the% operator, and a third method of formatting strings, called Formatted String Literals, or f string for short, has been added to Python 3.6.

> name = 'Bob'

> > f'Hello, {name}!'

'Bobbies, Hello'

You can also use embedded Python expressions within strings, such as:

> a = 5

> b = 10

> > f'Five plus ten is {a + b} and not {2 * (a + b)}.

'Five plus ten is 15 and not 30.'

This looks cool, but this operation has long been a feature in template engines, but it has been introduced into language standards because it is used by more people.

In addition to these, you can also manipulate numbers.

# accuracy

> PI = 3.141592653

> f "Pi is {PI:.2f}"

> >'Pi is 3.14'

> error = 50159747054

# formatted in hexadecimal

> f'Programmer Error: {error:#x}'

'Programmer Error: 0xbadc0ffee'

# formatted in binary

> f'Programmer Error: {error:#b}'

Programmer Error: 0b10111010110111000000111111111011101110

You can learn more at PEP498.

Variable comment

"dynamic language feels good for a moment, code refactoring crematorium", although it is suspected of scaremongering, it is also difficult to maintain the code because of the flexibility of dynamic language, so we have to explain the parameters through document comments. and sometimes because of changes in business requirements, there is no synchronous document comment after code modification, resulting in inconsistency between the actual code and the document, if it can be like a static language. There will be no problem for programmers to be limited to the rules at the syntax level, so there is an advantage in doing engineering projects in a language like Java.

Starting with Python 3.5, you can add type annotations to functions and methods:

> def my_add (a: int, b: int)-> int:

... Return a + b

This function indicates that the parameters an and b must be of type int, and the return value of the function is also int.

There is no change in semantics-the CPython interpreter simply records types as type annotations, but does not do type checking in any way. Type checking is purely optional and you need a tool like Mypy to help you.

You can learn more about this change in PEP 526.

Of course, this version is not only a little bit different, but also

Syntax of asynchronous generator

Asynchronous deductive grammar

Faster dictionary structure, 20% to 25% less memory

Read here, this "what are the characteristics of Python3.6" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report