Tencent classroom - Process Control

  Preliminaries

  There are some built-in python based approach, today we introduce two simple and very common:

    print output in the console

print('Hello,world')

    input in the console input

name = input('please input your name : ')
print('hello',name)

  bool value (Boolean) - True and False

    First, let's look at the true, false concepts:

      1>2

      'Abc' contains three characters

      Character 'd' in the 'abc'

    In the python programming, English True true, or False for false.

  Process Control

   First, what is the process to control it? Why process control it?

   

  Above this figure is a simplified flow diagram, before writing the code, we need to draw the process in more detail some of them:

    

   Application - application flow control in python complete simulated landing

   

   * Simulated landing, if the user enters Eva, on the output hello, Eva! Otherwise, output Byebye!

  Realization - code for landing

name = input('please input your name : ')
if name == 'Eva':
    print(
'Hello,Eva!')
else:
    print(
'Byebye!')

  除了刚刚我们已经学习过的print和input方法,又多了一些我们不认识的东西。。。

  首先,这里的name是什么呢?

  解决了name,我们就开始研究流程控制的精华语法了——if条件语句:

if '条件':
    '条件成立后执行的代码'
else:
    '条件不成立时执行的代码'

    

    例如:

if 1>10:
    print("正在执行if条件下的代码")
else:
    print("正在执行else下的代码")
例1:if条件语句

  除此之外,条件语句还可以这样用:

复制代码
if '条件1':
    '条件1成立后执行的代码'
elif '条件2':
    '条件2成立后执行的代码'
elif '条件3':
    '条件3成立后执行的代码'
……
else:
    '上述所有条件都不成立时执行的代码'
复制代码

    

if 1>10:
    print("正在执行if条件下的代码")
elif 10>1:
    print("执行第1个elif条件下的代码")
elif 5>1:
    print("执行第2个elif条件下的代码")
else:
    print("正在执行else下的代码")
例2:if条件语句

 

  更多相关内容,详见:

    Python全栈开发入门经典:https://ke.qq.com/course/157698#tuin=839b573b 

     Python全栈开发进阶实战:https://ke.qq.com/course/158006#tuin=839b573b

 

  

     

 

  

  预备知识

  python中有一些内置的基础方法,今天我们先介绍2个简单而且非常常用的:

    print  在控制台输出

print('Hello,world')

    input 在控制台输入

name = input('please input your name : ')
print('hello',name)

  bool值(布尔值)——真和假

    首先,我们来了解一下真、假的概念:

      1>2

      'abc'中含有3个字符

      字符'd'在'abc'中

    在python编程中,用英文True表示真,用False表示假。

  流程控制

   首先,什么是流程控制呢?为什么会有流程控制呢?

   

  上面这个图是一个简化的流程图,在写代码之前,我们需要把流程画的更详细一些:

    

   应用——在python中应用流程控制完成模拟登陆

   

   *模拟登陆,如果用户输入Eva,就输出hello,Eva!否则就输出Byebye!

  实现——代码实现登陆

name = input('please input your name : ')
if name == 'Eva':
    print(
'Hello,Eva!')
else:
    print(
'Byebye!')

  除了刚刚我们已经学习过的print和input方法,又多了一些我们不认识的东西。。。

  首先,这里的name是什么呢?

  解决了name,我们就开始研究流程控制的精华语法了——if条件语句:

if '条件':
    '条件成立后执行的代码'
else:
    '条件不成立时执行的代码'

    

    例如:

if 1>10:
    print("正在执行if条件下的代码")
else:
    print("正在执行else下的代码")
例1:if条件语句

  除此之外,条件语句还可以这样用:

复制代码
if '条件1':
    '条件1成立后执行的代码'
elif '条件2':
    '条件2成立后执行的代码'
elif '条件3':
    '条件3成立后执行的代码'
……
else:
    '上述所有条件都不成立时执行的代码'
复制代码

    

if 1>10:
    print("正在执行if条件下的代码")
elif 10>1:
    print("执行第1个elif条件下的代码")
elif 5>1:
    print("执行第2个elif条件下的代码")
else:
    print("正在执行else下的代码")
例2:if条件语句

 

  更多相关内容,详见:

    Python全栈开发入门经典:https://ke.qq.com/course/157698#tuin=839b573b 

     Python全栈开发进阶实战:https://ke.qq.com/course/158006#tuin=839b573b

 

  

     

 

  

Guess you like

Origin www.cnblogs.com/l-hf/p/11528934.html