Python数据结构基础(二)——If语句

版权声明:本文版权归作者所有,未经允许不得转载! https://blog.csdn.net/m0_37827994/article/details/86491283

一、If语句

  • 需要注意的是:在Python中If语句或循环语句是没有用大括号括起来的,所以编写程序时一定要严格按照编写格式来,什么时候要Tab空格一定不能忘记!!!
  • If条件语句那一行,最后记得加冒号

If条件语句格式:

if condition 1:
	statement 1
elif condition 2:
	statement 2
else:
	statement 3

Practise 1:

# If statement
x = 4
if x < 1:
    score = "low"
elif x <= 4:
    score = "medium"
else:
    score = "high"
print (score)

输出结果:

medium

Practise 2:

# If statment with a boolean
x = True
if x:
    print ("it worked")

输出结果:

it worked

猜你喜欢

转载自blog.csdn.net/m0_37827994/article/details/86491283