• 技术文章 >Python技术 >Python基础教程

    python3怎么获取控制台输入的数据

    FXLFXL2020-08-14 09:36:29原创3240
    python3获取控制台输入的数据的方法:可以利用input()函数来获取。python3为我们提供了input()函数,该函数用来接收一个标准输入数据,返回为string类型,使用方法如:【age = input()】。

    Python3.x 中 提供了 input() 函数接受一个标准输入数据,返回为 string 类型。

    (推荐教程:Python入门教程

    语法:

    1

    input([prompt])

    参数prompt表示提示信息。

    代码示例:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    """

    接收控制台的输入

    How old are you?

    18

    How tall are you ?

    180

    How much do you weigh?

    50

    So ,you are '18' old,'180' tall and '50' heavy,

      

    python3的控制台输入函数时input();

    """

    print("How old are you?");

      

    age=input();

      

    print("How tall are you ?");

      

    height=input();

      

    print("How much do you weigh?");

      

    weight=input();

      

    print("So ,you are %r old,%r tall and %r heavy," %(age,height,weight));

    专题推荐:python3 控制台
    上一篇:怎么安装python的扩展库 下一篇:python怎样在一个范围内取随机数

    相关文章推荐

    • python控制台输出为什么会有省略号• python控制台是什么意思• python控制台怎么退出• Python控制台输出乱码问题怎么解决

    全部评论我要评论

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

  • 取消发布评论
  • 

    Python学习网