Python intrinsic functions

Source: Internet
Author: User

Li = [' Alex ', ' Eric ', ' Roman ']
For I in Enumerate (li,10):
Print (i)

Results:

(' Alex ')
(One, ' Eric ')
(' Roman ')

Conclusion: Enumerate is convenient for adding a self-increment sequence number to an element

Print (Ord (' C '))
Print (CHR (99))
Results:

99
C

Conclusion: Ord can convert a character to an ASCII code, and CHR can convert ASCII to a string

a1 = "[[+], [3,4], [5,6], [7,8], [9,0]]"
B1 = eval (A1)
Print (B1)
Print (Type (B1))
Results:

[[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]
<class ' list ' >

Conclusion: string conversion to List


A2 = "([up], [3,4], [5,6], [7,8], [9,0])"
b2 = eval (A2)
Print (B2)
Print (Type (b2))
Results:

([1, 2], [3, 4], [5, 6], [7, 8], [9, 0])
<class ' tuple ' >

Conclusion: string conversion to Ganso


A3 = "{1: ' A ', 2: ' B ', 3: ' C '}"
B3 = eval (A3)
Print (A3)
Print (Type (B3))
Results:

{1: ' A ', 2: ' B ', 3: ' C '}
<class ' Dict ' >

Conclusion: string conversion to Dictionary

Li = [11,22,33,44]
# New_li = List (map (lambda X:x+100,li))
# Print (Type (new_li))
# Print (New_li)

def func (x):
x = x+100
return x
New_li = List (map (Func,li))
Print (New_li)
Results: [111, 122, 133, 144]
Conclusion: The map function will process the input to the output, one to the other, and the map first parameter is the function

Li = [11,22,33,44]
def func (x):
If x>22:
Return True
Else
Return False
F_li = List (filter (Func,li))
Print (F_li
Results: [33, 44]
Conclusion: The filter function can be used for filtering operation through function.


Python intrinsic functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.