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

How does python find the missing parameters

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

Share

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

This article mainly introduces python how to find the missing parameters, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Description

1. If any parameters are omitted during slicing, Python will try to calculate them automatically.

2. If you examine the source code of CPython, you will find a function called PySlice_GetIndicesEx (), which calculates the slice index of any given parameter.

It is the logical equivalent of Python.

This function uses the Python object and optional parameters to slice and returns the start, stop, step, and length of the slice.

Example

Def py_slice_get_indices_ex (obj, start=None, stop=None, step=None): length = len (obj) if step is None: step= 1 if step= = 0: raise Exception ("Step cannot be zero.") If start is None: start = 0 if step > 0 else length-1 else: if start

< 0: start += length if start < 0: start = 0 if step >

0 else-1 if start > = length: start = length if step > 0 else length-1 if stop is None: stop = length if step > 0 else-1 else: if stop

< 0: stop += length if stop < 0: stop = 0 if step >

0 else-1 if stop > = length: stop = length if step > 0 else length-1 if (step

< 0 and stop >

= start) or (step > 0 and start > = stop): slice_length = 0 elif step < 0: slice_length = (stop-start + 1) / (step) + 1 else: slice_length = (stop-start-1) / (step) + 1 return (start, stop, step, slice_length) Thank you for reading this article carefully I hope the article "how to find the missing parameters in python" shared by the editor is helpful to everyone. At the same time, I also hope that you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report