自己写读书笔记,记录下自己的python学习中遇到的一些问题或者一些奇怪的东西。
#! /usr/bin/env python3
age = input("input your age:")
if age >= 18:
print("adult")
else:
print("young")
执行后会报错
TypeError: '>=' not supported between instances of 'str' and 'int'
原因是input()输入的是str类型,需要将其转成int型。
int(input("input your age:"))