Home > Backend Development > Python Tutorial > Introduction to Python basic process control (code example)

Introduction to Python basic process control (code example)

不言
Release: 2019-03-09 14:21:43
forward
2796 people have browsed it

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:
	内容
Copy after login

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")
Copy after login

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("你打错了,请重新输入")
Copy after login

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("输入错误请重新输入")
Copy after login

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("请输入正确字符")
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template