zoukankan      html  css  js  c++  java
  • 判断条件

    Python 类型有:整数(int),小数(float),字符串(string)

    “ X” 加引号的都为字符串

    Python判断

    if ,elif: else:(只用这三种判断)

    eg:

    age =18

    if age>=18:

      print('成年人')

    else:

      print('未成年')

    判断:

    <,>,<=,>=,==,!=

    and(并且关系)

    eg:

     1     # 功能
     2     # >=90优秀    <=90 >=80为良好, >= 60 <= 80 为及格,<= 60 不及格,不在1- 
     3         100之间提示不合法
     4 
     5 secore = float(input('请输入分数:'))  #input输出的都是字符串,需要转换成int 或者float类型
     6 if secore>= 90 and secore<= 100:
     7     print('优秀')
     8 elif secore< 90 and secore>= 80:
     9     print('良好')
    10 elif secore< 80 and secore>= 60:
    11     print('及格')
    12 elif secore<60 and secore>=0:
    13     print('不及格')
    14 else:
    15     print('不合法')

    or(或者)

    eg:

    1 sex=input('请输入性别(只能输入男,女):')
    2 if sex == ''or sex =='':
    3      print('性别正常')
    4 else:
    5     print("无别识别性别")
    View Code

    判断某一个数据是否存在

    语句 :if  ...in ...

    eg:

    1 user = input('请输入账号:')
    2 if '123456'in user or '111111'in user or '121212'in user:
    3     print('已存在')
    4 else:
    5     print('不存在')

    如果不存在某个数据

    if....not in ...

    user = input('请输入账号:')
    if '123456' not in user and '111111' not in user and '121212' not in user:
        print('可以注册')
    else:
        print('已经注册,不能重复注册')
  • 相关阅读:
    如何在当前文件夹打开cmd(基于win10)
    Python命名空间和作用域
    Python定位模块_PYTHONPATH变量
    Python模块_import语句_from...import 函数名_from ... import *
    Python全局变量和局部变量
    Python变量作用域
    Python匿名函数_return语句
    Python函数参数
    Python按值传递参数和按引用传递参数
    Python函数调用
  • 原文地址:https://www.cnblogs.com/xxxxyanyan/p/12752594.html
Copyright © 2011-2022 走看看