首页 > 编程语言 >Python if语句

Python if语句

时间:2023-01-24 23:33:29浏览次数:42  
标签:语句 users Python bananas else user print name

#if-elif-else
alien_color="green"
if alien_color == "yellow": #检查是否相等
	print("this palyer is 5")
elif alien_color == "green":
	print("this palyer is 10")
else:
	print("this palyer is 15")

#if设置独立的条件
fruits = ["apple","oranger","bananas"]
if "apple" in fruits:
	print("You really like bananas")
if "bananas" in fruits:
	print("You really like bananas")

#先检查列表是否为空,再对列表中各元素进行指定操作
user_names = ["yaya","sunda","lele","admin","weilai"]
if user_names:
	for user_name in user_names:
		if user_name == "admin":
			print("Hello admin, would you like to see a status report?")
		else:
			print(user_name+", welcome!")
else:
	print("We need to find some users!")

#检查用户名
current_users = ["yaya","sunda","lele","admin","weilai"]
new_users = ["xiaohui","xiaohua","xiaohei","yaya","LeLE"]
for new_user in new_users:
	if new_user.lower() in current_users:
		print("This name exists")
	else:
		print("This name not exists")

 

标签:语句,users,Python,bananas,else,user,print,name
From: https://www.cnblogs.com/chaimy/p/17066529.html

相关文章

  • 适合编程初学者的开源云笔记系统(Python版)
    目标为编程初学者打造入门学习项目,使用各种主流编程语言来实现。让想学编程的,一个都不落下。上述基本涵盖了当前编程开发所有主流语言。左侧为前端版本:安卓、iOS、鸿蒙......
  • Python博客导航
    第一部分-Python程序设计基础第一章-Python介绍1.1-Python简介1.2-Python准备1.2-创建虚拟环境第二章-Python基础(建设中)2.1-编写代......
  • Python获取指定目录下的所有文件路径、获取指定目录下所有文件名(但是不包含子目录中文
    Python获取指定目录下的所有文件路径、获取指定目录下所有文件名(但是不包含子目录中文件名)、获取指定目录下所有pdf文件名(但是不包含子目录中pdf文件名)#-*-coding:utf-8......
  • python进程绑定CPU的意义
        ===================================== 相关:python进程绑定CPU的一些Demo【转载】python进程绑定CPU......
  • python简单实现对桌面进行实时捕捉画面
    介绍最近在研究目标检测方面的小东西,需要到对桌面进行实时捕捉画面,获取画面后再检测,达到实时桌面目标检测的目的,所以写了一段小代码来实现该功能,实测速度很快,符合我的需求......
  • Python语音识别
    Python语音识别需求:用代码将录音转成文字,常规普通话,不是播音员那种标准发音。结论:无论在线或是离线,用代码调用的效果都不太理想。1、离线模式参考:https://blog.csdn.n......
  • python进程绑定CPU的一些Demo
    从https://www.cnblogs.com/devilmaycry812839668/p/17066212.html中知道如何对python进程设置CPU绑定,本文对此进行一些延伸,给出一些例子:代码1:importosfrommultiproce......
  • 百度联想:用Python抓取百度关键字联想信息
    Python抓取百度关键字联想信息参考:https://www.jianshu.com/p/dc1ec2456331?appinstall=0MAC上运行经常得到乱码,只有偶尔非乱码;该方法其实没什么实用价值。#https://ww......
  • 【转载】 python进程绑定CPU
    版权声明:本文为CSDN博主「人间再无张居正」的原创文章,遵循CC4.0BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/u013887652/article/deta......
  • Python入门之选择语句
    """选择语句"""sex=input("请输入性别:")ifsex=="男":print("您好,先生!")elifsex=="女":print("您好,女士!")else:print("性别未知!")print("后续逻辑......