python - 我可以在python3的单行代码中一次增加2个变量相同的值吗
问题描述
我最近开始学习python。这是我的 python3 代码。如果条件满足,我需要将两个变量的值都加一。我怎样才能在一行中做到这一点,此代码工作正常。我可以在一行中使这段代码简短而甜美吗?提前致谢。
//This code works fine
if(letters[index] == letters[index+1]):
count += 1
index += 1
是否可以在 1 行中执行此操作。我的意思是这样的
[count,index]+=1
(这不起作用)
解决方案
你可以做
if(letters[index] == letters[index+1]):
count,index=count+1,index+1
或者
if(letters[index] == letters[index+1]):
count+=1;index+=1
推荐阅读
- docker - 无法连接到在 docker 中运行的本地 datastax cassandra
- python - 如何在 wagtail 管理员中过滤页面列表,以便编辑者只能看到其中一部分组中的页面?
- ios - 如何将自定义 SCNTechnique 传递添加到特定区域,而不会弄乱 Sceneview 全屏区域的其余部分?
- git - Git - 区分大小写问题
- amazon-web-services - 服务器端加密与客户端加密 - Amazon S3
- python - 将 Pycharm 与 Oracle SQL 数据库连接起来?- 错误:DPI-1047
- ruby-on-rails - 我正在尝试在我的 rails 应用程序(rails 6)中使用 searchkick gem 实现弹性搜索。重新索引模型时出现 SystemStackError
- python - 如何在 Python 中的 IF 语句中从多个返回值中检查变量之一的值
- php - 在 $_GET 变量中存储和签名
- eclipse - Visual Studio Code 中的 Eclipse 插件支持?