自己写读书笔记,记录下自己的python学习中遇到的一些问题或者一些奇怪的东西。

  1. 1
    2
    3
    4
    5
    6
    7
    #! /usr/bin/env python3

    age = input("input your age:")
    if age >= 18:
    print("adult")
    else:
    print("young")
    执行后会报错
1
TypeError: '>=' not supported between instances of 'str' and 'int'

原因是input()输入的是str类型,需要将其转成int型。

1
int(input("input your age:"))