Python chapter 5 learning notes

简介: 版权声明:本文为博主原创文章,原文均发表自http://www.yushuai.me。未经允许,禁止转载。 https://blog.csdn.net/davidcheungchina/article/details/78243675  一个简单例子    在python中,检查是否相等时,大小写不同默认是不相等的。
版权声明:本文为博主原创文章,原文均发表自http://www.yushuai.me。未经允许,禁止转载。 https://blog.csdn.net/davidcheungchina/article/details/78243675
  1.  一个简单例子

    python中,检查是否相等时,大小写不同默认是不相等的。如果需要不考虑大小写,则可把他们都统一转换成小写。

    检查多个条件时有以下两种情况:

    1. 必须同时符合多种情况:利用and语句。例如:if (age_0>21) and (age_1<=40)

    2. 多种情况符合其一即可:用or。例如:

if (age_0<18) or (age_1>60)

        如果你希望检查一个元素是否存在于一个列表中,可以使用in,如例所示:

>>>  requested_toppings=['mushrooms','onions','pinepple']

>>> 'mushrooms' in requested_toppings

屏幕显示Ture

如果你希望检查一个元素不存在于一个列表中,可以使用 not in。如例所示:

>>> 'apple' not in requested_toppings

答案为True

相关文章
|
23天前
|
机器学习/深度学习 算法 搜索推荐
Machine Learning机器学习之决策树算法 Decision Tree(附Python代码)
Machine Learning机器学习之决策树算法 Decision Tree(附Python代码)
|
4月前
|
Linux Apache Python
Python3 notes
Python3 notes
|
10月前
|
机器学习/深度学习 数据采集 数据挖掘
【Deep Learning 框架】Python中各类框架区别
当我们在学习深度学习的时候,往往会看到Sklearn、Pytorch、Tensorfloiw、Keras等各种各样的框架平台,看得我们眼花缭乱,这些框架平台究竟是干什么用的呢?🤔
94 0
|
11月前
|
安全 Python
Python3 notes
Python3 notes
|
11月前
|
Python
Python3 notes
Python3 notes
|
11月前
|
Python
Python3 notes
Python3 notes
|
11月前
|
Linux Python
Python3 notes
Python3 notes
|
12月前
|
Python
Python3 notes
Python3 notes
|
机器学习/深度学习 算法 Python
【莫烦Python强化学习笔记】Q Learning
【莫烦Python强化学习笔记】Q Learning
|
索引 Python