Home >Backend Development >Python Tutorial >Introduction to Python basic process control (code example)
This article brings you an introduction to Python basic process control (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Conditional statement
if 条件: 内容 else: 内容
The indentation must be the same or an error will be reported
#!/usr/bin/evn python #-*- coding:utf-8 -*- if 1 == 1: print("OK") else print("NO")
One = sign is assignment
Two == is comparison
!= means no Equal to
Multiple conditions
#!/usr/bin/evn python #-*- conding:utf-8 -*- name = input("UserName:") if name == "12345": print("恭喜你答对了") elif name == "ABCDE": print("恭喜你对了是ABCDE") elif name == "qazwsx": print("恭喜你是qazwsx") else: print("你打错了,请重新输入")
and All conditions must be met
#!/usr/bin/env python #-*- coding:utf-8 -*- name = input("UserName:") pw = input("password:") if name == "abc" and pw == "123": print("恭喜你输入正确") else: print("输入错误请重新输入")
or Only one of the conditions must be met
#!/usr/bin/env python #-*- coding:utf-8 -*- name = input("UserName:") if name == "abc" or name == "123": print("恭喜你输入正确") else: print("请输入正确字符")
The above is the detailed content of Introduction to Python basic process control (code example). For more information, please follow other related articles on the PHP Chinese website!