Python re-introduces the covered built-in function, and python built-in function

Source: Internet
Author: User

Python re-introduces the covered built-in function, and python built-in function

Fortunately, this problem is easy to solve. We only need to use _ builtins __:

from __builtins__ import int as py_int

In this way, we can re-use the python int, but in this case it is called py_int.

The most common reason for overwriting a function or variable is that "*" is used for reference "*":

from something import *

When using import in this way, we cannot provide clear guidance on which variables or functions are introduced, or whether these variables or functions will overwrite the original variables or functions. therefore, this is one of the main reasons why "*" is not recommended during import.

In python 3, you can use builtins instead of _ builtins __.


Write a FUNCTION in PYTHON

>>> Def s (M ):
... If M = 1:
... Return 1
... Else:
... Return s (M-1) + 1.0/M

>>> Import math
>>> Def Gauss (x, m = 0, s = 1 ):
... Return (1/(math. sqrt (2 * math. pi) * s) * math. exp (-0.5 * (x-m)/s) ** 2)
...
>>> Li = [-5,-4,-3,-2,-,]
>>> Print map (Gauss, li)
[1.4867195147342977e-006, 0.00013383022576488537, 0.0044318484119380075, 0.053990966513188063, 0.24197072451914337, 0.3989422804014327, 0.24197072451914337, 0.053990966513188063, 0.0044318484119380075, 1.4867195147342977e-006]
>>>

Python function !!!!

Def isSquare (N ):
For I in range (1, N ):
If N = I * I:
Return True
Return False

Def isItemInList (L, item ):
If item in L:
Return True
Else:
Return False

Do you want to color this triangle?

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.