Python入门基础:函数知识点(一):简单基础类型

完美Python入门基础知识点总结 附Java/C/C++/机器学习/算法与数据结构/前端/安卓/Python/程序员必读书籍书单大全: 书单导航页(点击右侧 极客侠栈 即可打开个人博客):极客侠栈 ①【Java】学习之路吐血整理技术书从入门到进阶最全50+本(珍藏版) ②【算法数据结构+acm】从入门到进阶吐血整理书单50+本(珍藏版) ③【数据库】从入门到进阶必读18本技术书籍网盘吐血整理网盘(珍藏版) ④【Web前端】从HT... 阅读详情

函数是一组语句,它们接受输入、进行一些特定的计算并产生输出。

函数存在的意义:

 1. 提高代码的复用性
 2. 将复杂的逻辑简单化,分功能化

 

函数定义:

小知识 : []表示可选  <>表示必备

函数名字最好能直接表示该函数的功能,多个单词之间用_链接

<def> <函数名>([参数列表])<:>
# 待执行语句
# 如果有需要显式返回<return 标识符>或<return>

Python提供了内置函数,如print()等。用户定义函数:可以创建自己的函数

# A simple Python function to check
# whether x is even or odd
def evenOdd( x ):
    if (x % 2 == 0):
        print "even"
    else:
        print "odd"
  
# Driver code
evenOdd(2)
evenOdd(3)

产出:

even
odd

函数的返回值

函数可以返回任何类型的数据,函数内执行到return后结束,后面代码不再执行.

def func():
    res = 1+1
    print('我执行了')
    return res
    print('我不会执行')

print('程序正常执行')
# 函数内的语句确实是执行了,打印我执行了
func()
# 想要拿到函数return的值需要重新找个变量接收一下
# 注意这里再次打印了一次我执行了  因为函数再次调用了一次
res = func()
print(res)
# 不写return默认返回None
def func():
    print('我执行了')

res = func()
print(res)

多个返回值

多个变量接收

def func():  return 1,2,3
a,b,c = func()print(a,b,c)

输出:

一个变量接收是一个元组

def func():  return 1,2,3
res = func()print(res)

输出:

参考传递还是价值传递?

注意:在Python中,每个变量名都是引用。

当我们将变量传递给函数时,将创建对对象的新引用。

Python中传递的参数与Java中传递的引用相同。

# Here x is a new reference to same list lst
def myFun(x):
   x[0] = 20
  
# Driver Code (Note that lst is modified
# after function call.
lst = [10, 11, 12, 13, 14, 15] 
myFun(lst);
print(lst) 

产出:

[20, 11, 12, 13, 14, 15]

当我们传递引用并将接收到的引用更改为其他引用时,传递参数和接收参数之间的连接就会中断。

例如,考虑下面的程序。

def myFun(x):
  
   # After below line link of x with previous
   # object gets broken. A new object is assigned
   # to x.
   x = [20, 30, 40]
  
# Driver Code (Note that lst is not modified
# after function call.
lst = [10, 11, 12, 13, 14, 15] 
myFun(lst);
print(lst) 

产出:

[10, 11, 12, 13, 14, 15]

如果我们分配一个新值(在函数中),则另一个示例演示引用链接被破坏。

def myFun(x):
  
   # After below line link of x with previous
   # object gets broken. A new object is assigned
   # to x.
   x = 20
  
# Driver Code (Note that lst is not modified
# after function call.
x = 10 
myFun(x);
print(x) 

产出:

10

练习:尝试猜测以下代码的输出。

def swap(x, y):
    temp = x;
    x = y;
    y = temp;
  
# Driver code
x = 2
y = 3
swap(x, y)
print(x)
print(y)

产出:

2
3

关键字传参(参数名对应)

def sue_for_peace(num1,num2):    print(num1,num2)    res = num1+num2    return res
print(sue_for_peace(num2=3,num1 = 4))

混合使用(先位置参数再关键字参数)

def sue_for_peace(num1,num2,num3):
    print(num1,num2,num3)
    res = num1+num2+num3
    return res

print(sue_for_peace(3,num3=1,num2 = 2))

默认参数:

默认参数是一个参数,如果该参数的函数调用中没有提供一个值,则该参数假定为默认值。

# Python program to demonstrate
# default arguments
def myFun(x, y=50):
    print("x: ", x)
    print("y: ", y)
  
# Driver code (We call myFun() with only
# argument)
myFun(10)

产出:

('x: ', 10)
('y: ', 50)

与C++默认参数一样,函数中的任意数量的参数都可以具有默认值。

但是一旦有了默认参数,它右边的所有参数也必须有默认值。

混合使用时,先按位置传递参数,后按关键字传递参数,最后是默认值

错误示范:

def sue_for_peace(num1=1,num2,num3): # 第一行这里就错了,默认值只能再最后,编辑器报错
    print(num1,num2,num3)
    res = num1+num2+num3
    return res

print(sue_for_peace(2,3))
def sue_for_peace(num1, num2, num3=3):
    print(num1, num2, num3)
    res = num1+num2+num3
    return res

print(sue_for_peace(num2=2,3)) # 先位置后关键字,编辑器报错

print(sue_for_peace(1,num1=2)) # 不允许给同一个形参传两个值

关键词参数:

允许调用者用值指定参数名,就不需要记住参数的顺序。

# Python program to demonstrate Keyword Arguments
def student(firstname, lastname): 
     print(firstname, lastname) 
    
    
# Keyword arguments                  
student(firstname ='Geeks', lastname ='Practice')    
student(lastname ='Practice', firstname ='Geeks')  

产出:

('Geeks', 'Practice')
('Geeks', 'Practice')

可变长度参数:

# Python program to illustrate  
# *args for variable number of arguments
def myFun(*argv): 
    for arg in argv: 
        print (arg)
    
myFun('Hello', 'Welcome', 'to', 'GeeksforGeeks') 

产出:

Hello
Welcome
to
GeeksforGeeks
# Python program to illustrate  
# *kargs for variable number of keyword arguments
  
def myFun(**kwargs): 
    for key, value in kwargs.items():
        print ("%s == %s" %(key, value))
  
# Driver code
myFun(first ='Geeks', mid ='for', last='Geeks')    

产出:

last == Geeks
mid == for
first == Geeks

匿名功能:在Python中,匿名函数意味着函数没有名称。正如我们已经知道的,def关键字用于定义普通函数,lambda关键字用于创建匿名函数。请看这关于细节。

# Python code to illustrate cube of a number  
# using labmda function 
    
cube = lambda x: x*x*x 
print(cube(7)) 

产出:

343

 

<Zhuuu_ZZ>HIVE(十一)函数 Hive内置函数一 Hive函数分类二 字符函数二 类型转换函数和数学函数三 日期函数四 集合函数五 条件函数六 聚合函数和表生成函数6.1 聚合函数6.2 表生成函数:输出可以作为表使用 一 Hive函数分类 从输入输出角度分类 标准函数:一行数据中的一列或多列为输入,结果为单一值 聚合函数:多行的零列到多列为输入,结果为单一值 表生成函数:零个或多个输入,结果为多列或多行 从实现方式分类 内置函数 自定义函数 UDF:自定义标准函数 UDAF:自定义聚合函数 UDTF:自定义表生成函数 阅读详情

相关推荐

Python基础知识点梳理

python常见知识点梳理 摘要: 本文主要介绍一些平时经常会用到的python基础知识点,用于加深印象。python的详细语法介绍可以查看官方编程手册,也有一些在线网站对python语法进行了比较全面的介绍,比如菜鸟教程: python3 教程|菜鸟教程 本文主要是介绍基础语法,操作实例在另一篇博客中单独介绍: python语言介绍 python是一门解释型语言,python的设计目标: 一门...

m0_46245938的博客 4万+

python中def fun 定义函数列表_python函数

# -*- coding:utf-8 -*-#yys#python 3.7.2# 1.定义函数、调用函数# 函数:组织好的、可重复使用的、用户实现单一或者关联功能的代码段。# 函数能够提高应用的模块性和代码的重复利用率。# Python提供了很多内置的函数,比如len等等,# 另外也可以根据自己的业务需求进行用户自定义函数的创建。# 1.1 函数的定义规则# 函数代码块以 def 关键词开头,后接...

weixin_28820911的博客 6532

入门Python基础知识点总结

Python基础入门主要学习变量,运算符,输入输出和条件以及循环语句,认识Python零基础入门Python开发,了解常用的Linux命令。熟练掌握Python的变量、输入输出、运算符、条件和循环语句,了解使用过常用linux命令。 一、第一个Python程序 1、Python的介绍 2、sublime、vi编辑代码,Python运行代码 3、第一个helloworld程序、注意点 4、Python的交互模式,iPython 二、注释和Python2的中文问题 1、注释 2、Python

weixin_56535888的博客 1197

python主函数参数_Python main函数、命名行参数

1,main函数python是基于脚本顺序执行,没有main函数的概念,但是我们可以通过关键字 __name__来模拟。__name__:模块名,当执行文件和当前模块一致时,__name__的值等于__main__。比如有如下文件:当执行test1.py时输出 __main__,当执行test2.py时,输出 test1我们可以通过if __name__ == "__main__"来模拟main...

weixin_39857899的博客 1200

【Python从入门到精通】(一)就简单看看Python吧

人生苦短,我用python

码农飞哥 2万+

基于 Quest 摄像头数据开发的原理介绍【Unity Meta Quest MR 开发教程】

比如想在识别到的现实物体上叠加虚拟物体,需要知道这个现实物体在 Unity 的世界坐标下的哪个位置,是带有 x,y,z 三个轴的数据的。而 WebCamTexture 捕捉到的图像只是个 2D 的平面,没有三维世界的深度信息,我们通过物体识别算法识别到的物体坐标只是在这个 2D 平面上的一个屏幕坐标,可以理解为 Quest 拍摄了一张照片,我们识别到这张照片上的某个像素点为需要识别的现实物体的中心。是不是看起来比较复杂?Quest 的相机访问功能是在安卓的。

qq_46044366的博客 2104

Python 函数3000字使用总结

我的施工之路目前已完成,以下五期Python专题总结:1我的施工计划2数字专题3字符串专题4列表专题5流程控制专题6编程风格专题今天是Python函数专题,目录结构:Python 函数专...

算法channel 493

ncl泰勒图(均方根误差、标准差、相关系数)

ncl泰勒图(均方根误差、标准差、相关系数)

weixin_61281699的博客 8007

python中[-1]、[:-1]、[::-1]、[n::-1]使用方法

例子: import numpy as np a=np.random.rand(5) print(a) [ 0.64061262 0.8451399 0.965673 0.89256687 0.48518743] print(a[-1]) ###取最后一个元素 [0.48518743] print(a[:-1]) ### 除了最后一个取全部 [ 0.64061262 0.8451399 0.965673 0.89256687] print(a[::-1]) ### 取从后向前(相反)

星之所望的博客 824

Python_构建同花顺问财智能选股API服务

本文详细介绍了如何使用Python构建同花顺问财智能选股API服务,涵盖从环境准备、核心API开发到高级功能扩展的全过程。通过Flask框架和pywencai库,开发者可以快速搭建稳定可靠的选股接口,实现自动化股票筛选与交易系统集成,提升量化投资效率。

weixin_30596343的博客 333

基于CODESYS与EtherCAT的步进电机单轴控制实践

本文详细介绍了基于CODESYS平台与EtherCAT总线技术实现步进电机单轴控制的完整实践流程。从硬件选型、软件工程创建、EtherCAT主从站配置,到运动控制功能块编程与在线调试,手把手指导读者完成从零到一的搭建,并提供了常见问题的排坑指南,帮助自动化开发者快速掌握这一高效、灵活且成本可控的工业运动控制解决方案。

hh234的博客 491

万字【Python基础】保姆式教学,零基础快速入门Python

Python基础入门、函数、列表、元组、字典、字符串等等

龙叔的博客 33万+

手把手教你用DLP4500和海康相机搭建双目结构光系统(附完整代码获取路径)

本文详细介绍了如何利用DLP4500投影仪和海康工业相机搭建低成本双目结构光三维测量系统。从硬件选型、软件配置到结构光编码解码实现,再到三维重建全流程,提供了完整的实战指南和优化技巧,帮助用户以不到2万元的预算实现0.05mm精度的三维扫描。

weixin_32447969的博客 317

Python基础 知识点总结

python入门、基础知识

Code_Guan的博客 1万+

uniapp:安卓苹果APP判断是否授权开启手机位置服务+弹框引导跳转到用户手机设置位置服务开启页面,uniApp app判断是否授权位置信息权限如果位置是关闭状态则提示用户(跳转各机型位置设置页面)

uniapp APP判断是否开启位置信息服务&&判断是否授权位置信息权限,uniappapp定位权限被拒绝后,询问是否开启授权并跳转到手机设置页面,uniapp APP端 定位未授权 去手机设置里开启定位,uniapp提示用户开启定位,跳转到开启定位页面,uniapp获取当前位置及检测授权状态,uniapp中获取位置信息处理,uni-app实现定位功能_uniapp获取定位位置信息,uniapp中app是否开启定位,app获取地理位置,uniapp打开位置权限设置页面IOS,用户并没有开启微信信息服务或者没

✅ 精选推荐文章 4342

SAP NetWeaver Business Client (NWBC) 的深入解析

SAP NetWeaver Business Client(NWBC)作为 SAP 提供的一种用户界面,旨在为终端用户提供无缝集成传统 SAP GUI 事务和新开发的基于 Web Dynpro ABAP 的应用程序的体验。SAP NetWeaver Business Client(NWBC)是 SAP 推出的用户界面,旨在为终端用户提供单一入口,集成传统的 SAP GUI 事务和新开发的基于 Web Dynpro ABAP 的应用程序。在实际业务场景中,NWBC 的应用提升了用户的工作效率和体验。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1605

Python入门知识点、期末复习必备(超基础知识点)

Python期末知识点,超基础,超详细,一、Python简介二、print()函数1.引号的用法2、转义字符3、变量和赋值三、数据类型与转换1、数据类型2.2、数据转换四、条件判断1、单向判断:if 2、双向判断:if ... else ...3、多向判断:if…elif…else…4、if 嵌套五、input()函数的使用1、input()函数结果的赋值2、input()

weixin_43474701的博客 7185

Freeswitch 如何检测链路是否有回铃音

Freeswitch回铃音检测解决方案 问题描述:呼叫手机时,虽然信令正常(183/180),但部分手机无回铃音,导致坐席无法判断是否接通,用户体验差。 解决方案: 先播放本地音频作为回铃音 实时检测用户侧是否有声音输入 检测到声音后自动切换为用户侧音频 技术实现: 使用Freeswitch APP实现功能 创建结构体保存实例数据(包括铃声文件、会话句柄、VAD检测器等) 通过media bug机制实现音频流的替换 利用VAD(语音活动检测)技术监控用户侧声音 当检测到用户说话时自动终止本地铃声播放 该方案

2301_81507069的博客 51

python基础入门(超详细)

Python入门知识点 特来整理常见的top50入门知识点,初学者可以参考学习 1.input输出 ``` password=(input("你的密码是:")) print("你的密码是:",password) ```

告白的博客 3万+

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Python 常用基础知识点(一)—— 基础知识点

Python 常用基础知识点(一)—— 基础知识点编码格式设置常用转义字符运算符(非常规)常用常量运算符优先级数据分类迭代器 & 生成器匿名函数集合作用域模块 本文主要讲解 python 开发中常用到的基本语法知识点,算是高频的基础知识点,以熟悉知识点为主 编码格式设置 -*- coding: utf-8 -*- # 指定编码格式为 UTF-8 -*- coding: GB2312 -*- # 指定编码格式为 GB2312 常用转义字符 \n 换行符 \t 制表符(Tab

LC1356的专栏 2773

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

python简单入门

python简单入门

懒狗的博客 5761

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python基础——类型注解【变量,函数,Union】

类型注解是一种为函数、类或模块参数和返回值指定预期类型的方法。它们用于提高代码可读性和帮助开发者在开发过程中捕获潜在的类型错误。类型注解不会强制执行类型检查,但它们可以与第三方工具结合使用,以实现更严格的类型检查。例如,当我们在给函数输入变量的时候,我们就可以使用Ctrl+p。

tan_run的博客 6661

Python入门必背:基础知识点合集与背记手册

Python入门必背:基础知识点合集与背记手册 【下载地址】Python入门必背基础知识点合集与背记手册 本资源文件名为【python入门必背】python入门基础知识点合集、python基础知识背记手册,旨在为Python初学者提供一个全面的基础知识点合集,帮助记忆Python的基础知识,顺利入门Python编程 ...

gitblog_09708的博客 966

Python基础知识点-- 函数

​ 此文章为Python基础知识点(从入门到实践)-- 函数,此节Python基础知识点主要包括:定义函数、传递实参、返回值、传递列表、传递任意数量的实参、将函数存储在模块中、函数编写指南。

m0_57787115的博客 3075

python基础函数有哪些,python入门函数大全

输入参数:sub:指定的子串start:索引的起始位置。默认值为0。end:索引的结束位置。默认值为字符串长度len(str)。print(str1.rfind('z')) # 结果 6reduce函数在python2中是个内置函数,但在python3中已被移到functools模块。function:指定函数(输入为两个元素)iterable:可迭代对象:初始参数(可选),即指定第一个元素的值,然后与序列的第一个元素执行指定函数。# 常与匿名函数lambda同时使用。

2401_86114424的博客 963

Python 基础入门必学知识点笔记

[新手必备]Python 基础入门必学知识点笔记  Python 作为近几年越来越流行的语言,吸引了大量的学员开始学习,为了方便新手小白在学习过程中,更加快捷方便的查漏补缺。根据网上各种乱七八糟的资料以及实验楼的 Python 基础内容整理了一份极度适合新手小白的 Python 基础入门必学知识点笔记。 1. 换行与缩进 1. 1条代码为1行,例如:1个赋值、1个请求、1个运算、1个打印,结尾不需要添加任何标点符号。 2. 根据代码的执行逻辑进行区分,同一级别的代码需要保持对齐,对与不..

量慧实工作室LHStudio的博客 1643
上一篇: 2020最流行的密码,黑客都不想破解,快看看你是不是在用
下一篇: Python干货:「如何写好第一个程序」命令行模式和交互模式
土豆编程
博客等级 码龄6年 105粉丝 117原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值