python函数调用之自我调用与C++比较
C++下的函数自我自我调用
第一种方法
#include <iostream>
using namespace std; int rel_do(){ int a;
cout<<"please input :";
cin>>a;
if(a==) {
cout<<a;
return ;
}
else if(a==) {
cout<<a;
return ;
}
第二种方法
#include <iostream>
using namespace std;
int rel_do(){
int a;
cout<<"please input :";
cin>>a;
if(a==) {
cout<<a;
return ;
}
else if(a==) {
cout<<a;
return ;
}
else {
cout<<"input error!!!"<<endl;
rel_do();
}
}
int main(){
rel_do();
return ;
}
两种方法比较可以发现,rel_do()方法中,调用rel_do方法前加不加return都可以正常运行。
而在python中必须使用return。否则返回None,并且不报错
def real_do():
do = input('1:确认\n'
'2:取消' )
if do == '':
return 1
elif do == '':
return 2
else:
return real_do() 11 print(real_do())


在Java中,return可以放在rel_do()方法前面也可以放在函数最后返回1.
package javazero;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
rel_do();
}
static int rel_do(){
Scanner scanner = new Scanner(System.in);
System.out.println("please input :");
int a;
a=scanner.nextInt();
if(a==1) {
System.out.println(a);
return 1;
}
else if(a==2) {
System.out.println(a);
return 1;
}
else {
System.out.println("input error!!");
rel_do();
}
return 1;
}
}
package javazero;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
rel_do();
}
static int rel_do(){
Scanner scanner = new Scanner(System.in);
System.out.println("please input :");
int a;
a=scanner.nextInt();
if(a==1) {
System.out.println(a);
return 1;
}
else if(a==2) {
System.out.println(a);
return 1;
}
else {
System.out.println("input error!!");
return rel_do();
}
}
}
python函数调用之自我调用与C++比较的更多相关文章
- python函数调用时参数传递方式
python函数调用时参数传递方式 C/C++参数传递方式 对于C程序员来说,我们都知道C在函数调用时,采用的是值传递,即形参和实参分配不同的内存地址,在调用时将实参的值传给实参,在这种情况下,在函数 ...
- python 函数调用顺序
def foo(): print ('in the foo') bar() def bar(): print ('in the bar') foo() 1.foo函数进入内存 2.bar函数进入内存 ...
- 用Python在Linux下调用新中新DKQ-A16D读卡器,读二代证数据
1.背景 最近在研究二代证读卡器,手头上的设备是新中新DKQ-A16D,在官网(https://www.onecardok.com.cn/download)逛了一圈,发现Win下的示例,浏览器插件很多 ...
- [Effective JavaScript 笔记]第18条:理解函数调用、方法调用及构造函数调用之间的不同
面向对象编程中,函数.方法.类的构造函数是三种不同的概念. JS中,它们只是单个构造对象的三种不同的使用模式. 三种不同的使用模式 函数调用 function hello(username){ ret ...
- [Python陷阱]os.system调用shell脚本获取返回值
当前有shell个脚本/tmp/test.sh,内容如下: #!/bin/bashexit 11 使用Python的os.system调用,获取返回值是: >>> ret=os.sy ...
- python中使用ctypes调用MinGW生成的动态链接库(dll)
关于gcc编译dll的我就不说了,网上举例一大堆,下面以g++为例. 假设有一个test.cpp文件如下: extern "C" { __declspec(dllexport) d ...
- 判断python对象是否可调用的三种方式及其区别
查找资料,基本上判断python对象是否为可调用的函数,有三种方法 使用内置的callable函数 callable(func) 用于检查对象是否可调用,返回True也可能调用失败,但是返回False ...
- Python 的 JPype 模块调用 Jar 包
背景与需求 最近学习并安装使用了HttpRunner框架去尝试做接口测试,并有后续在公司推广的打算. HttpRunner由Python开发,调用接口时需要依赖Python:而大多数公司的扩展工具包使 ...
- python基础--------字符串的调用详解(2)
Python 字符串的的调用方法~~~@@@ 17. strip : 去除字符串左右两边指定的字符 18. rstrip : 去除字符串右边指定的字符 19 . lstrip : 去除 ...
随机推荐
- SpringBoot单元测试中的事务和Session
1.Springboot中使用junit编写单元测试,并且测试结果不影响数据库. 2.
- Linux知识积累(6) 系统目录及其用途
linux系统常见的重要目录以及各个目作用:/ 根目录.包含了几乎所有的文件目录.相当于中央系统.进入的最简单方法是:cd /./boot引导程序,内核等存放的目录.这个目录,包括了在引导过程中所必需 ...
- Spring知识点回顾(06)Profile 和 条件注解 @Conditional
1.设定环境中的active profiles 如:DispatcherServerlet的init-param spring.profiles.active=production spring.pr ...
- Spring Security 入门(1-3-1)Spring Security - http元素 - 默认登录和登录定制
登录表单配置 - http 元素下的 form-login 元素是用来定义表单登录信息的.当我们什么属性都不指定的时候 Spring Security 会为我们生成一个默认的登录页面. 如果不想使用默 ...
- 敏捷项目需求拆解&发现用户故事
需求文档和敏捷中的Epic,User Story, Task之间是什么关系以及如何将需求文档转换成敏捷方式的描述,指导开发人员. 一直是很多公司团队比较困扰的问题,那么最近笔者为了解决这些问题,上了一 ...
- 分享:纯 css 瀑布流 和 js 瀑布流
分享一次纯 css 瀑布流 和 js 瀑布流 纯 css 写瀑布流 1.multi-columns 方式: 通过 Multi-columns 相关的属性 column-count.column-ga ...
- 使用nodeJS的 crypto模块来为你的密码hash加盐
这篇文章将向你解释如何使用Node.js的Crypto模块对你的密码进行加盐hash.在这里,我们将不会对不懂的密码存储方式进行详细的比较.我们将要做的是知道在Node.js中使用加盐hash在进行密 ...
- Hive函数:rank()、dense_rank()
数据准备: G1,KING, G1,BING, G2,FING, G1,FORD, G2,SCOTT, G1,JONES, G2,BLAKE, G1,CLARK, G1,ALLEN, G1,CELL1 ...
- [翻译] softmax和softmax_cross_entropy_with_logits的区别
翻译自:https://stackoverflow.com/questions/34240703/whats-the-difference-between-softmax-and-softmax-cr ...
- [Linux]使用awk批量杀进程的命令
碰到需要杀掉某一类进程的时候,如何批量杀掉这些进程,使用awk命令是很好的选择. ps -ef|grep aaa|grep -v grep|awk '{print "kill -9 &quo ...