• 技术文章 >常见问题 >Python常见问题

    python如何实现手动输入文字

    yangyang2020-04-11 10:05:26原创5076

    Python中可以使用input()函数接收用户输入的文字。

    函数语法:

    1

    input([prompt])

    参数说明:prompt: 提示信息

    示例:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    >>>a = input("input:")

    input:123                  # 输入整数

    >>> type(a)

    <type 'int'>               # 整型

    >>> a = input("input:")   

    input:"runoob"           # 正确,字符串表达式

    >>> type(a)

    <type 'str'>             # 字符串

    >>> a = input("input:")

    input:runoob               # 报错,不是表达式

    Traceback (most recent call last):

      File "<stdin>", line 1, in <module>

      File "<string>", line 1, in <module>

    NameError: name 'runoob' is not defined

    <type 'str'>

    更多Python知识请关注Python视频教程栏目。

    专题推荐:python
    上一篇:python如何引入数据集 下一篇:python ndarray是什么

    相关文章推荐

    • python实现查询纠错• python列表是否允许重复• python如何计算程序运算时间• python中iter函数怎么用

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网