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 Python3

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

Share

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

This article introduces which commonly used built-in functions in Python3, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Mathematical correlation

Abs (a): get the absolute value. Abs (- 1)

Max (list): get the maximum value of list. Max ([1pm 2pm 3])

Min (list): find the minimum value of list. Min ([1pm 2pm 3])

Sum (list): gets the sum of list elements. Sum ([1pm 2pm 3]) > 6

Sorted (list): sort and return the sorted list.

Len (list): list length, len ([1, 2, 3])

Divmod (aformab): get quotient and remainder. Divmod (5Jing 2) > (2Jing 1)

Pow (aformab): gets the multiplier. Pow (2 and 3) > 8

Round (aformab): gets the decimal of the specified number of digits. A stands for floating-point numbers and b for the number of digits to be retained. Round (3.1415926) > 3.14

Range (a [, b]): generates an array of a to b, left closed and right open. Range (1) > [1] 2, 3, 4, 5, 6, 7, 8, 9]

Type conversion

Int (str): converts to int. Int ('1') > 1

Float (int/str): converts int type or character type to floating point type. Float ('1') > 1.0

Str (int): converts to character type. Str (1) >'1'

Bool (int): converts to a Boolean type. Str (0) > > False str (None) > False

Bytes (str,code): receives a string and returns a byte stream type with the format you want to encode. Bytes ('abc',' utf-8') > > breadabc' bytes (u 'crawler', 'utf-8') > b'\ xe7\ x88\ xac\ xe8\ x99\ xab'

List (iterable): converted to list. List ((1, 2, 3)) > [1, 2, 2, 3]

Iter (iterable): returns an object that can iterate. Iter ([1pm 2jue 3]) >

Dict (iterable): converted to dict. Dict ([('ajar, 1), (' baked, 2), ('cantilevered, 3)]) > > {' avell1, 'baked 2,' caterpillar 3}

Enumerate (iterable): returns an enumerated object.

Tuple (iterable): converted to tuple. Tuple ([1Jing 2jue 3]) > (1pm 2pm 3)

Set (iterable): converted to set. Set > > {1pm 2pm 3pm 5J} set ({1pm 2pm 2pm 5J C'}) >

Hex (int): converts to hexadecimal. Hex (1024) > '0x400'

Oct (int): converts to octal. Oct (1024) > '0o2000'

Bin (int): converts to binary. Bin (1024) > '0b10000000000'

Chr (int): converts digits to corresponding ASCI characters. Chr (65) >'A'

Ord (str): converts ASCI characters to corresponding numbers. Ord ('A') > 65

Related operation

Eval (): executes an expression or string as an operation. Eval ('1cm 1') > 2

Exec (): executes the python statement. Exec ('print ("Python")') > Python

Filter (func, iterable): filter the elements that meet the criteria by judging the function fun. Filter (lambda x: X > 3, [1Jing 2 Jing 3 Jing 4 5 Jing 5]) >

Map (func, * iterable): use func for each iterable object. Map (lambda a _ r _ b: a _ r _ b, [1m _ 2, m _ 3 _ 4], _ 5 _ 6 _ 7] > 6 _ 8 _ _ 10]

Zip (* iterable): merges iterable groups. Returns a zip object. List (zip ([1, 2, 3], [4, 5, 6])) > > [(1,4), (2,5), (3,6)]

Type (): returns the type of an object.

Id (): returns the unique identification value of an object.

Hash (object): returns the hash value of an object, and object with the same value has the same hash value. Hash ('python') > > 7070808359261009780

Help (): calls the system's built-in help system.

Isinstance (): determines whether an object is an instance of this class.

Issubclass (): determines whether a class is a subclass of another class.

Globals (): returns a dictionary of the current global variable.

Next (iterator [, default]): receives an iterator and returns the values in the iterator. If default is set, the default content is output when the elements in the iterator are traversed.

Reversed (sequence): an iterator that generates an inverted sequence. Reversed ('abc') > [' clockwise, baked and written a']

Python3 about which commonly used built-in functions are shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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