---
title: "Python if elif else"
author: "fairy_xzc"
date: "2016-09-28T13:21:17Z"
tags: []
categories: ["编程语言"]
slug: "python-if-elif-else"
draft: false
lastmod: "2016-09-28T13:21:59Z"
id: 2327544
url: "https://agilestyle.iteye.com/blog/2327544"
---

**原创转载请注明出处：[http://agilestyle.iteye.com/blog/2327544](/blog/2327544)**

 

ifelse.py

```
age = input()
print('Your age is: ', age)

# input()返回的数据类型是str，str不能直接和整数比较，必须先把str转换成整数
# Python提供int()函数来完成这件事情
age = int(age)

# if <条件判断1>:
#     <执行1>
# elif <条件判断2>:
#     <执行2>
# elif <条件判断3>:
#     <执行3>
# else:
#     <执行4>
if age >= 18:
    print('adult')
elif age >= 6:
    print('teenager')
else:
    print('kid')
```

 

Console Output

![](http://dl2.iteye.com/upload/attachment/0120/2867/ca34d7ca-f47f-3ac3-9323-c2a6fb2fe83e.png)