• day①:python的用户交互


      py2           py3
    ①input() --> eval(input())
    #eval()作用:把字符串当作变量
    
    py2:
    >>> var=input("please input your name:")
    please input your name:hy
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<string>", line 1, in <module>
    NameError: name 'hy' is not defined
    >>> var=input("please input your name:")
    please input your name:"hy"           ##输入字符串或者字符的时候,要用双引号或者单引号包起来
    >>> var
    'hy
    
    py2:
    >>> var=input("please input your name:")
    please input your name:yaobin
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<string>", line 1, in <module>
    NameError: name 'yaobin' is not defined
    >>> yaobin="hy"
    >>> var=input("please input your name:")
    please input your name:yaobin
    >>> var
    'hy'
    ##py2的input()是一个特殊的raw_input(),只是外层调用了eval()函数而已。
    
    py3:
    >>> eval(input("your name:"))
    your name:yaobin
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<string>", line 1, in <module>
    NameError: name 'yaobin' is not defined
    >>> yaobin="hy"
    >>> eval(input("your name:"))
    your name:yaobin
    'hy'
    
    
    
      py2           py3
    ②raw_input --> input() 
    py2:
    >>> raw_input("your name:")
    your name:abc               #不管你输入什么样的类型,都会转变成字符串
    'abc'
    
    py3:
    >>> input("your name:")
    your name:abc
    'abc'
    >>>
  • 相关阅读:
    Visual Studio color schemes
    WebForm服务器验证控件与前端js自定义验证共同使用
    Powerdesigner设计表生成SQL脚本(带有注释)
    JS日期格式化
    C# 生成小于Int数值绝对值的随机数
    LINQ解析
    Could not calculate build plan:
    Maven Tomcat webapp
    用JS来改变CSS样式
    安装 groovy eclipse 插件
  • 原文地址:https://www.cnblogs.com/binhy0428/p/5090870.html
Copyright © 2020-2023  润新知