Python 中 function(#) (X)格式 和 (#)在Python3.*中的注意
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 funcfunc(2018)(11)>>> this is func with another func as return2018this is another function11
其实,这种情况最常用在卷积神经网络中:
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 zeroesX = ZeroPadding2D((3, 3))(X_input)# CONV -> BN -> RELU Block applied to XX = Conv2D(32, (7, 7), strides = (1, 1), name = 'conv0')(X)X = BatchNormalization(axis = 3, name = 'bn0')(X)X = Activation('relu')(X)# MAXPOOLX = MaxPooling2D((2, 2), name='max_pool')(X)# FLATTEN X (means convert it to a vector) + FULLYCONNECTEDX = 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.*中的注意相关推荐
- 【Python】导出docx格式Word文档中的文本、图片和附件等
[Python]导出docx格式Word文档中的文本.图片和附件等 零.需求 为批量批改学生在机房提交的实验报告,我需要对所有的实验文档内容进行处理.需要批量提取Word文档中的图片和附件以便进一步检 ...
- python中print的用法_Python2与Python3中print用法总结
Python2中的print用法 在Python2 中 print 是一种输出语句 strHello = 'Hello Python' print strHello # Hello Python 1. ...
- python打开并读取csv文件_!python3中使用使用read_csv( )读取csv文件,文件路径中含有中文,无法读取怎么处理?...
python3如何根据csv文件的列的内容,自动建数据库表 你好,csv格式的和excel格式是差不多的, 下面是读取excel的一些函数,希望帮到你: # -*- coding: cp936 -*- ...
- python代码规范工具_如何检查python3中的代码规范
如何检查python3中的代码规范 发布时间:2020-11-16 09:40:48 来源:亿速云 阅读:77 作者:小新 这篇文章给大家分享的是有关如何检查python3中的代码规范的内容.小编觉得 ...
- python怎么横着输出_对python3中, print横向输出的方法详解
对python3中, print横向输出的方法详解 Python 2 : print打印的时候,如果结尾有逗号,打出来时候不会换行.但是在python3里面就不行了. Python3: 3.0的pri ...
- python格式化字符串语法_详解Python3 中的字符串格式化语法
一.旧式的字符串格式化 % 操作符 参考以下示例: >>> name = "Eric" >>> "Hello, %s." % ...
- python多个strip_python 格式化多个Python3中strip()、lstrip()、rstrip()用法详解
Python中有三个去除头尾字符.空白符的函数,它们依次为: strip: 用来去除头尾字符.空白符(包括n.r.t.' ',即:换行.回车.制表符.空格) lstrip:用来去除开头字符.空白符(包 ...
- python没有用_你可能没有在Python3中使用但却应该使用的东西
Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. 由于Python EOL的发布,许多人开始将他们的Python版本从2切换到3.不幸的是,我发现大多数Py ...
- python input函数详解_对Python3中的input函数详解
下面介绍python3中的input函数及其在python2及pyhton3中的不同. python3中的ininput函数,首先利用help(input)函数查看函数信息: 以上信息说明input函 ...
最新文章
- 如何判断一个数是否在40亿个整数中?
- 【技术实验】表格存储Tablestore准实时同步数据到Elasticsearch
- 启明云端分享| ESP32-S2直驱USB摄像头
- 计算机复试比重低的学校,又有985院校发布调剂信息,这个34所降低复试比重!...
- 多表关联的update语句
- GPS开发常用方法和Criteria确定android location providerGPS
- 从零开始刷Leetcode——数组(581.605.628)
- C++ new和delete 堆和栈
- 实战:小程序购物商城
- 读取.xls文件报错:XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b‘MIME-Ver
- 李笑来-- 学习学习再学习(前言)
- 2021年征兵没有高考成绩查询,2021年征兵政策新调整,三种情况无法通过政审,快看看是不是自己...
- 日本开发“后5G”技术 速度达5倍
- Flutter适配深色模式(DarkMode)
- 【腾讯Bugly干货分享】Android进程保活招式大全
- 数字图像处理——基本运算
- 在linux系统下实现SHELL自动化批量备份交换机配置文件
- 如何为安卓程序设置启动页面(splash)?
- linux shell脚本自动批量解压文件
- Linux极速版学习!