python3.4内嵌函数实例

本文详细介绍了Python中的多个内置函数,包括绝对值计算、迭代检查、ASCII转换等,并通过实例展示了这些函数的应用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

"""=======Built in Functions and Example======"""

import python_built_in_source as b
"""===abs()==="""
# print(abs(-5))
# print(abs(-1.0))
# print(abs(-.4))
# print(abs(1-9))
#print(b.abs.__doc__)

"""===all(iterable)=="""

# def bll(iterable):
#     for element in iterable:
#         if not element > 5:
#             return False
#     return True
# aa = bll([10, 20, 30])
# print(aa)

# a = [10, 20, 30]
# a_first = all([ x > 2 for x in a])
# a_second = all([ x > 20 for x in a])
# print(a_first)
# print(a_second)

# print(all ( [ True, True, True ] ))
# print(all ( [ True, True, False ] ))
# print(all ( [ "", "a", "b"]))#False
# print(all ( [ " ", "a", "b"]))#Ture

# def bll(iterable):
#     for element in iterable:
#         if not element.__eq__('n'):
#             return False
#     return True
# aa = bll(['n', 'n', 'n'])
# print(aa)

# aa = ['k', 'n', 'n']
# print( all( [x.__eq__('n') for x in aa]))
# print(any( [x.__eq__('n') for x in aa]))


# def any(iterable):
#     for element in iterable:
#         if element:
#             return True
#     return False

"""===ascii==="""
# randomList = ['Python', 'Pythön', 5]
# print(ascii(randomList))

"""===bin()==="""
# print(bin(2))
# print(bin(-2))
# print(bin(99999))

"""===callable()==="""
# print(callable(0))
# print(callable('faith'))

# def a_add(a, b):#函数返回True
#     return a + b
# print(callable(a_add))

"""===nested function==="""
# def a_add(a):#函数返回True
#     def a_plus(c):
#         return a+c
#     n = a_plus(a)#调用内部函数,但是不能在外层调用
#     return n
# b = a_add(1)
# print(b)


# def outer(num1):
#     def inner_increment(num1):  # hidden from outer code
#         return num1 + 1
#     num2 = inner_increment(num1)
#     return num1, num2
#
# inner_increment(10)#会报错 name 'inner_increment' is not defined
# a, b = outer(10)
# print(a, b)


# x = 1111111111111111
# def f1():
#     #x=1
#     print('------>f1 ',x)
#     def f2():
#         #x = 2
#         print('---->f2 ',x)
#         def f3():
#             x=3
#             print('-->f3 ',x)
#         f3()
#     f2()
# f1()

# class A:#类 返回TRUE
#     def method(self):
#         return 0
# print(callable(A))
# a = A()
# print(callable(a))#类没有实现__call__, 返回 False

# class B:#类 返回TRUE
#     def __call__(self, *args, **kwargs):
#         return 0
# print(callable(B))
# a = B()
# print(callable(a))#类实现__call__, 返回 True

# class A:#类 返回TRUE
#     def __call__(self, *args, **kwargs):
#         pass
#     def method(self):
#         return 0
# print(callable(A))
# a = A()
# print(callable(a))#类实现__call__, 返回 Ture
# print(callable(a.method()))#返回 False

#print(chr(97))

"""===compile()===="""
"""===complex()===="""

"""===delattr==="""
"""删除类的属性"""
# class Coordinate:
#     x = 3
#     y = 5
#     z = 10
# c = Coordinate()
# print(c.x)
# print(c.y)
# print(c.z)
# print('*'*10)
# delattr(Coordinate,'z')
# print(c.x)
# print(c.y)
# #print(c.z) #AttributeError: 'Coordinate' object has no attribute 'z'
print(dir())

class Shape:
    def __dir__(self):
        return ['area', 'perimeter']
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lm_y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值