Python 中 function(#) (X)格式 和 (#)在Python3.*中的注意事项

作者:沈子恒 时间:2021-11-15 18:53:31 

python 的语法定义和C++、matlab、java 还是很有区别的。

1. 括号与函数调用


def devided_3(x):
  return x/3.

print(a)    #不带括号调用的结果:<function a at 0x139c756a8>
print(a(3)) #带括号调用的结果:1

不带括号时,调用的是函数在内存在的首地址; 带括号时,调用的是函数在内存区的代码块,输入参数后执行函数体。

2. 括号与类调用


class test():
 y = 'this is out of __init__()'
 def __init__(self):
   self.y = 'this is in the __init__()'

x = test  # x是类位置的首地址
print(x.y) # 输出类的内容:this is out of __init__()
x = test() # 类的实例化
print(x.y) # 输出类的属性:this is in the __init__() ;

3. function(#) (input)


def With_func_rtn(a):
 print("this is func with another func as return")
 print(a)
 def func(b):
   print("this is another function")
   print(b)
 return func
func(2018)(11)
>>> this is func with another func as return
 2018
 this is another function
 11

其实,这种情况最常用在卷积神经网络中:


def model(input_shape):
 # Define the input placeholder as a tensor with shape input_shape.
 X_input = Input(input_shape)
 # Zero-Padding: pads the border of X_input with zeroes
 X = ZeroPadding2D((3, 3))(X_input)
 # CONV -> BN -> RELU Block applied to X
 X = Conv2D(32, (7, 7), strides = (1, 1), name = 'conv0')(X)
 X = BatchNormalization(axis = 3, name = 'bn0')(X)
 X = Activation('relu')(X)
 # MAXPOOL
 X = MaxPooling2D((2, 2), name='max_pool')(X)
 # FLATTEN X (means convert it to a vector) + FULLYCONNECTED
 X = Flatten()(X)
 X = Dense(1, activation='sigmoid', name='fc')(X)
 # Create model. This creates your Keras model instance, you'll use this instance to train/test the model.
 model = Model(inputs = X_input, outputs = X, name='HappyModel')
 return model

总结

以上所述是小编给大家介绍的Python 中 function(#) (X)格式 和 (#)在Python3.*中的注意网站的支持!

来源:https://blog.csdn.net/shenziheng1/article/details/84646453

标签:python,function,python3
0
投稿

猜你喜欢

  • 详解用python自制微信机器人,定时发送天气预报

    2023-05-12 14:27:29
  • HTML5 Canvas 起步(1) - 基本概念

    2009-04-21 13:14:00
  • 浅析Oracle中sys、system和Scott用户下的数据库连接问题

    2023-07-02 15:14:06
  • python用装饰器自动注册Tornado路由详解

    2021-07-16 07:53:37
  • Oracle 当前用户下所有表的记录总数

    2009-07-14 21:34:00
  • Python 3.x 新特性及10大变化

    2023-02-05 09:17:36
  • 解析SQL Server中数据库快照的工作原理

    2009-02-19 17:04:00
  • Django 跨域请求处理的示例代码

    2022-05-27 17:08:46
  • Python 模块EasyGui详细介绍

    2022-04-27 22:55:39
  • W3C发布HTML 5草案 最终版将于2010年敲定

    2008-01-26 19:16:00
  • CSS解决未知高度的垂直水平居中自适应问题

    2009-03-17 17:06:00
  • 用python实现一个简单计算器(完整DEMO)

    2023-11-10 11:03:48
  • 深入php var_dump()函数的详解

    2023-11-08 16:09:01
  • Python协程asyncio异步编程笔记分享

    2022-03-05 22:23:31
  • 将有安全问题的SQL过程删除,比较全面

    2007-08-06 14:46:00
  • 我的页面制作方法

    2008-03-23 13:51:00
  • SQLServer 全文检索(full-text)语法

    2011-12-01 10:38:22
  • 分享一个Emeditor压缩样式的宏

    2010-08-16 12:30:00
  • 编译asp应用程序成为exe文件

    2008-10-23 14:01:00
  • js实现单机双人象棋设计分析

    2008-05-20 12:57:00
  • asp之家 网络编程 m.aspxhome.com