if 语句
 
电脑程序不只是执行命令。时常会需要做出选择。例如基于一个条件的选择。Python有这样几种条件运算:
 
>   greater than
<   smaller than
==  equals
!=  is not
 
条件语句总是和变量相结合。使用if语句可以让程序做出选择。例如:
 
x = int(input("Tell X"))
 
if x == 4:
    print('You guessed correctly!')
 
print('End of program.')
 
在你执行这个程序的时候总是会输出'End of program.',但是只有在X=4的时候才会输出‘You guessed correctly!’(见下表)。 Python也能够执行x不等于4时的代码,else的用法如下:
 
x = int(input("Tell X"))
 
if x == 4:
    print('You guessed correctly!')
else:
    print('Wrong guess')
 
print('End of program.')
 
看下面的示范:

3.If statements的更多相关文章

  1. 代码的坏味道(6)——Switch声明(Switch Statements)

    坏味道--Switch声明(Switch Statements) 特征 你有一个复杂的 switch 语句或 if 序列语句. 问题原因 面向对象程序的一个最明显特征就是:少用 switch  和 c ...

  2. mysql二进制文件操作语法(mysql binary log operate statements)

    开启 binary logs 功能 在 mysql 配置文件中配置 log-bin,重启 mysql my.cnf (on Linux/unix) or my.ini (on Windows) 例子: ...

  3. Mapped Statements collection does not contain value fo

    Mapped Statements collection does not contain value for后面是什么类什么方法之类的: 错误原因有几种: 1.mapper.xml中没有加入name ...

  4. Raising Error Conditions with MySQL SIGNAL / RESIGNAL Statements

    http://www.mysqltutorial.org/mysql-signal-resignal/ Summary: in this tutorial, you will learn how to ...

  5. mybatis报错Mapped Statements collection does not contain value for com.inter.IOper

    首页 > 精品文库 > mybatis报错Mapped Statements collection does not contain value for com.inter.IOper m ...

  6. Given a compiled machine-language program, which statements in the source language cause the execution of the most machine-language instructions and what is the execution time of these instr

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION A  variety  of  studi ...

  7. What is the difference between parameterized queries and prepared statements?

    Both parameterized queries and prepared statements are exactly the same thing. Prepared statement se ...

  8. Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for …

    编译通过并且运行web成功后,访问的页面不需要连接数据库,不牵扯到反射调用实体类就不会报错, 报错内容如下: [WARNING] org.springframework.web.util.Nested ...

  9. 【原创】Mapped Statements collection does not contain value for DaoImpl.method

    问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Pers ...

  10. a single statement, not multiple statements

    http://dev.mysql.com/doc/refman/5.7/en/prepare.html Statement names are not case sensitive. preparab ...

随机推荐

  1. public,private,protected,以及不写时的差别

    作用域public,private.protected.以及不写时的差别 这四个作用域的可见范围例如以下表所看到的. 说明:假设在修饰的元素上面没有写不论什么訪问修饰符,则表示friendly.不使用 ...

  2. ZOJ ACM 1204 (JAVA)

    毕业好几年了,对算法还是比較有兴趣,所以想又一次開始做ACM题.俺做题比較任意,一般先挑通过率高的题来做. 第1204题,详细描写叙述请參考,ZOJ ACM 1204 1)难度分析 这个题目,基本的难 ...

  3. Node.js显示页面

    首先我们先要下载并安装Nodejs,然后进入Node.js中安装supervisor, npm -g install supervisor -g表示全局模式 (无论windows哪一个用户登陆都可以使 ...

  4. nginx配置(windows配置)

    以下是我的项目用到的一份配置文件#user  nobody;worker_processes  4; #进程数,一般cpu是几核就写多少#error_log  logs/error.log;#erro ...

  5. Eclipse 使用小结

    代码智能提示 Java智能提示 Window -> Preferences -> Java -> Editor -> Content Assist -> Auto Act ...

  6. Python数据可视化——使用Matplotlib创建散点图

    Python数据可视化——使用Matplotlib创建散点图 2017-12-27 作者:淡水化合物 Matplotlib简述: Matplotlib是一个用于创建出高质量图表的桌面绘图包(主要是2D ...

  7. 免费SSL&付费SSL证书,该如何选择?

    近年来Google.Apple.百度等公司不断推动 HTTPS 的普及,SSL 证书作为 HTTPS 安全协议的必备配置,自然也成为了网站.App 开发者最重要部署项目之一. 又拍云于 2016 年联 ...

  8. 工厂方法模式(Method Factory),理解多态应用的好例子.

    工厂方法模式又称为多态性工厂,个人认为多态性工厂更能准确的表达这个模式的用处.与简单工厂(静态工厂)相比较,这里的多态性是指抽象出一个工厂基类,将因为一个产品有N种不同的是现这种变化封装起来,将具体的 ...

  9. js怎么防止变量冲突

    [1]工程师甲编写功能A ? 1 2 3 var a = 1; var b = 2; alert(a+b);//3 [2]工程师乙添加新功能B ? 1 2 3 var a = 2; var b = 1 ...

  10. vmstat 命令详解

    作用:vmstat 的含义为显示虚拟内存状态(virtual memor statics),但是它可以报告关于进程,内存,I/O 等系统整体运行状态 选项: -a 显示活动内页 -f 显示启动后创建的 ...