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 commonly used built-in functions in Python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you what the built-in functions commonly used in Python are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Complex ()

Returns a complex number in the shape of a+bj. The input parameters are divided into three cases:

Returns 0j when the parameter is empty

When the parameter is a string, the string expression is interpreted as plural and returns

Returns a+bj when the argument is two integers (aforme b)

When the parameter has only one integer a, the imaginary part b defaults to 0 and the function returns axi0j.

Dir ()

Returns a list of names within the current local scope when no parameters are provided

When a parameter is provided, all properties contained in the object are returned

Divmod (afort b)

A-represents a divisor, integer, or floating point number

B-represents a divisor, integer, or floating point number

Enumerate (iterable,start=0)

Iterable-an iterable object, list, tuple sequence, etc.

Start-count index value, default initial value is 0

Eval (expression,globals,locals)

Expression-string expression

Globals-variable function, global namespace, must be in dictionary form if provided; optional parameters

Locals-variable scope, local namespace, any mappable object if fetch; optional parameter parses the string expression and returns the execution result

Filter (function,iterable)

Function-provides the name of the filter function and returns true or false

Iterable-iterable objects such as lists, tuples, etc

Isinstance (object,classinfo)

Object-- represents an object of type. If it is not this type, the function always returns False.

Calssinfo-is a type tuple or a single type

Determine whether the type of the object object is one of classinfo or classinfo, and return True or False

When debugging a Python program, one of the obstacles is that the initial variable does not have a defined type, so when writing or debugging code, the isinstance () function is often used to determine the type of variable to help us understand the whole logic of the program and prevent errors.

Map (function,iterable, …)

Function-execute function

Iterable-iterable object

Put each element in iterable into the function function to execute in turn, and get the same number of iterators as iteable elements.

There can be multiple iterable objects in map (), where the parameters in the function function are parallel elements in all iterable objects. The final number of iterators is based on providing the least number of iterable objects, and execution stops when all the elements of the least number of iterable objects are input.

Input ()

The function is used for human-computer interaction, reading a line of input from the input and converting it into a string

Zip (* iteables)

* iterables-two or more iterable objects

All the elements in the iterable object are aggregated in parallel according to the parameter order, and an iterator is obtained. Each element in the iterator is a tuple of n elements, and n represents the number of input iterable parameters in the function.

Zip () function: equivalent to

These are all the contents of the article "what are the built-in functions commonly used in Python?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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

Development

Wechat

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

12
Report