gpt4 book ai didi

Python if 语句 : less than

转载 作者:太空宇宙 更新时间:2023-11-04 08:10:54 25 4
gpt4 key购买 nike

好的,谁能告诉我如何制作一个有字符限制的 if else 语句

我写了一个快速代码让你明白我想告诉你什么

pass1 = input("What is you'r password: ")
pass2 = input("Rewrite you'r password: ")

我尝试了什么:

if pass1 == <5:
print ("password is greater than 5")
else:
print ("password is lower than 5")

基本上我在注册时尝试像在真实网站中一样进行限制(当您注册时有一个字符限制示例,它不能低于 5 个字符)。

最佳答案

您需要使用 len 测试字符串的长度功能:

if len(pass1) < 5:

也许您对 if 语句和算术运算符也有一些困惑。在这里检查它们:

  1. Control Flow
  2. Comparissons

关于Python if 语句 : less than,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22584147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com