本文介绍了在 Python 3 中制作没有“else"的单行“if"语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在一行中做到这一点,但不使用无"?:

Is there any way to do this in a single line, but without using a 'None'?:

folders = ['Project 1', 'Project 2']
files = os.listdir('/home/user/Documents/Python')
for i in files:
    files.remove(i) if i in folders else None

可以跳过"else"语句吗?

Could one 'skip' the 'else' statement?

提前致谢.

推荐答案

if i in files: files.remove(i)

这篇关于在 Python 3 中制作没有“else"的单行“if"语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:39