学习完如何写'hello world'之后,我们还是不太满意,因为这样代码就写死了,以后运行的时候都只打印一局固定的话而已。

  但是,我想在程序运行后,自己手动输入内容怎么办,此时就要学习如何使用用户交互了。

  在python2.x中,用户交互使用的是 raw_input("提示内容") 方法,例如

name = raw_input("请输入姓名:")
print name

  之前的起手式就略去了,代码的执行结果是:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbEAAAA5CAIAAAA3JoLnAAAGoUlEQVR4nO2by5XrKBCGCUshTCJNGHIEVzuvZjLQttk7Cm2UgZPQLPTgVTwsS2r3zPede/rclqEoCvgpsFpNAACwovZUGh9N8xjfbXrQqlWqN+/akfh8D6/B9OqAOBzS1rNr8sEcdDnUNWV+gto4Hz6jDg3IebPlynn4NrEmznP3ptRN6SFR69k1987potFrFXXTLwzRrhEdH41q/bYcn5fQhx7u5dMWYc3oeIW1WUZHm2ns7nUVdzq2DkcqaPlgPruv4rKpKXM9bt+LHDujnl1zlLWXevEhlk8h1MSxuzfdc5qmaRp0WtqdYtNSeB7p8dFkh3zsHs6nO+aHsypMv265Q7f6bFZzkYe1vO3hiVSOzoLdnLdenNYdNxEYH40S18BFwfRH8Nxa0/RqEvTzM0ruqd+LI2N4nuVzCDXRTa8cP6KBDA+nlZoY2NkxP9wqYXUvcDuPz+97eB7P2tFZCseJ20nd8RMB0yvdayEbvSaY+1rZ7durSdCPz6jibEmV+TTLZxFqYn3bRgdddc+zy6/azNncTan+e/nP/M8u0a67K3WzOd1yNJ4X/3L/EpaZC0a5aucXcD00ulWq17pd7VzhoYdQ696N/gWTVybmlZnhbc6CJtrrDj+/W1pfY2KWh+laYVtz2P0z3WytuTeq/7u7K3VvmlY1/VfTLhHbmrMOR1ENy0j++CP4nejFcoew3b0I414VDb/vg1at1r1SN6379JgO2puH0cxMtRXPjTggcZntomneosSeBiNYjIY4e6+3HE6Dwuqul9T9mjiZ3rmZiperPdyZLl6c26/t2of5+ZoK2SwvLjNN4tHYPEIpCT1stfEtn+mhz5bibY3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RIURg0B4FQKmpi/44vzxymrpKmPxPQz01aqGADAm+zJE1M6+KomilVENRTrph4CAOzmrTxxSutjYKr+SUrmSprIdywAcAC5Pz7Jq1VRB2vUrUZGXa84OwPAqdSenTN54hSlllNa2uK6bsViWppyFQDgENAUAAALmggAYEETAQAsaCIAgAVNBACwoIkAABY0EQDAgiYCAFjQRAAAC5oIAGBBEwEALGgiAIAFTQQAsKCJAAAWNBEAwIImAgBY0EQAAAuaCABgQRMBACxoIgCABU0EALCgiQAAFjQRAMCCJgIAWNBEAAALmggAYPkXv0R9I2fIFsUAAAAASUVORK5CYII=" alt="" />

  再输入东西后回车

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbMAAABNCAIAAACjYB0NAAAIMklEQVR4nO2dO5bjNhBFsSwuwRsRlkEFjo1Mkb0DpoNcx6lzJtyBNkEH/AGFAkiqSbXUc+/B6RlR+H8eC0UJMv/+1xEIBAIhDObba0AgEAjvFlBGAoFAkMHUfzoCgUAghMH0AAAQgzICAEhQRgAAyX5l7O5Vde++Wm5rTW1M47+aj8b71/A1+MYc0A+HlPVwVbkzW7ve1VvifAdb+/nwGXVoh5w3W145D49DKOMwg6/GXI1tM0kerrq5oKHeTknM1e4YqKfGtbtXpo7LCuo8DoCs4bO821LcMjpRZOvH0bG+79xtW8InKzYNR67Typ35cJfVxbMlzusJ277KsTPq4aqjctvVijfJ+VwiZezcrXKPvu/7vrV5mQ+i9WPkYby7e1Uc+M7dg3efmCXB2vDNdPtt3VRnP2WX1HArX67hiWwcnZHlRj234rTmhEZBd6+MuhJe1JnxCJ6bqu/3GkTfP6P0lsatOLIPz8v5ZCJlDE2toDbJcMrt6kZlFPk8MUvCJDJ51H1Pbqi/XsPzeGwdnTFyasSd1JzYKPCNsY1VLNPXdOZzpTxdt70G0bfPqNXZkovzbjmfTqSM22vgrWhwuMMdX1o/WHZXY5pf43+GsCxU527GXBf7btwsDxIw+mVknCFiYre6OEJYQ29rYxpr6ymfV9QwQkl1c13seI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TVzfemAQAkKCMAgARlBACQoIwAABKUEQBAgjICAEhQRgAASaSMxkihTK+o19Voxphc8l35rL4FAHAsuhSaDCKaSKIXUFS091LGzBcdj/n1BAD4HPbZdH0smr0mkVsySd9aldeCTB9LdHrZeOUr378EgM+jpFmrBqMwMPv8trqcf1rcluRbmrefp38oAQB+DlKDVlWpbNwpBawpZvp3NXkSzVtz1Heg49PKAeC3ZLefsbyx3aWkYYa55IXIReaTt+IzMcWZVcMV5VDqkfEYp/ib++NF5fxcAPghZB9Gl820nLn3nDLmShGRd+ygCyeNJqe16j+akssqPLj+h51hBgATJWUs+/5SW7Iv6mnuLdUULZSViybo7pX4KZ7cE+fwrUK0Cf13ogDgJ7HbZsyp4V5lVJOomqimzV0cmM5F79wtOWN4OiR/krzod2W0B9PRlfAg81N+1B4A3oDnbcY+r5Iiq+1XcmK3poziCYzmZEx/KSA9RP2a/MTQNTEPh4s35xqj/+I8AHw++scV+/1+RhFti8ZtEdOwVrt20wAAT7NpN12wGfvEzOzzApemDROumqi5qgIAHAviAgAgQRkBACQoIwCABGUEAJCgjAAAEpQRAECCMgIASFBGAADJAcrYucoYY+QJiQeemQgA8FKOshlTHezcxXEWDQB8IucpIwDAp4IyAgBIpDJ6O53oUE174cmPuEjfeKUKdsuxMo65RFqZZgMA8J6s/tRU56rh0vxW56rKdcu/mYTiyvwS6xIA3p10Nz3Ye7PmFSQvfGtVGUNzFGUEgLdG2oxuVMTQQpz/5w6wGZf8AADeFKGMszPQROZg7HgUfsYgzXRpMQ8DFRyN0culil2UAABvBt+BAQCQoIwAABKUEQBAgjICAEhQRgAACcoIACBBGQEAJCgjAIAEZQQAkKCMAAASlBEAQIIyAgBIUEYAAAnKCAAgQRkBACQoIwCABGUEAJCgjAAAEpQRAECCMgIASFBGAAAJyggAIEEZAQAk/wPQ9of5H74sagAAAABJRU5ErkJggg==" alt="" />

   这里有一个要注意的地方,那就是当程序运行到等待用户输入的地方时,会一直等着,也就是下面的代码不会继续执行了,连退出都要用ctrl+c强制退出。

    另外,这里输入的数据会将其转换成字符串类型,要注意有时函数传参中的类型错误,别问我是怎么知道的。


  在第一篇中曾经提过,在3.x中, raw_input() 已经被 input() 取代了,而input()的特性又有所不同:

name = input("请输入姓名:")
print type(name)
print name  

  其中,type()函数是用来查看数据类型的,这种可以直接用的,被称为内置函数或内建方法。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeYAAACBCAIAAACad47OAAARJ0lEQVR4nO2dy3HDOBZFGcn0clJgQmYWbUUw3HnVIWiN3SyURLumhhGMk8As+APxHj6ESEmQzymXy4bwl3j19CThNhYAACqh8f9v0iVquVqtaZpQ8139JG8CAPgN6DprZ7WVeNW8JvoYUal9Lcn+6dvPprk07W1wi4db65UAADyetAiqcber4CEdj3cib0rqfuT541jMtem+vZK2/zlpNACAXBLxbzLE9kJyG86QxPuXw+U0Ty6viKH/QqAB4BXRI2ivRNZRy4NjpKRc/k42F9VM13Qmc0IJTPd5VFcAAEdSksuO5yh2SbzbYah5pHKUof9qmkvTXJrmOivwdzeWrHmPscTV6J++/eqXvLW5Ns2laZyStfCTYBwAHkos4RAPbEMBcplkh0bxKu9Ihnx3q1KP/PTtKM3LTbM6m6vzfqNs6JV8d1NlWRMA4EwSkh3PL8vo20aFPnSTGrxHxgpV8xhurRtiy099LCXuTZFqM6b7nOJ3PkYCAI+kJMoOyfReyVabqGKttg0VjpjvUamH/mtKg6yh9Hc/JjRmLTadk+LQPi6yKZn+/enbT78mAMCp3BVl27B8e13ll4RUOCXZ3tuPWiJ7/sy1LJmUd850r3Wckk3m5NI0X31/3SbBAQBOJvaVxbiYJmU6R3xzVN6d1a7ECADAm5GbGIlE2VYE5jasvLKt2zAZ1IemCgDwG0DyAACqAckGAKgGJBsAoBqQbACAakCyAQCqAckGAKgGJBsAoBreTLKH2weH6z0X7gKAE3mYZJtr0xScyfHd7Wi1HLH3m/np28t2q2VJTqtyhv6Lr/EDnIMv2e4xG0efnyEPXDq0FUqxkjzbKrNVITx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mY8LcS7f78voJ1UlgVFusolVk4RubWe3QVKXnrdBop566c85F60eZ4bZNlo1ZyGVNncBsGyb7cc/e2mfzlrIoA3h7ApJtza3vVQeAv+P2Uev7YzLKNsLcS5bIA/JlnRykLVbZKjLHEilpmaj116U2LLYdiE8pp7ncscw5e0jbMHVXc9aetFWTYwG8OSHJHm4fTuQyh1efk9ip9lFe/OVcgUGnmEhJsVqF+ilbRf5w3iuM5Lri1ZaCrnQ+suf4q4fIzu86RlxtLne14Okq8hgjMQK/hZBkj6mD7fUw9F9BsZO2T/KTADmSrUbZh0h22SqyxhLGZkuUvbxZd1+UvTuK9PvRrNdCTfKi7OlpWCJtwzItwZKSLfuRYwG8Ob5kr5/tc2Viyhh+XNvmz3/8EbGPWrK3/of8pLmXavc19+Pmsvf755qISdiuVeShGZvNMw/lYTOsxfydz80OKf2o1msZO6bk3x3DtugEXNswf1fnfw+wVZNjAbw1fJUGAKAakGwAgGpAsgEAqgHJBgCoBiQbAKAakGwAgGpAsgEAqgHJBgCoBiQbAKAakGwAgGpAsgEAqgHJBgCoBiQbAKAakGwAgGpAsgEAqgHJBgCoBiQbAKAakGwAgGpAsgEAqgHJBgCoBiQbAKAakGwAgGpAsgEAquH/Wn72kjTKx94AAAAASUVORK5CYII=" alt="" />

  当我们和上面输入的一样时,却发现报错了,关于报错提示怎么看以后会进行总结,这里报错的意思是变量没有被定义。

  如果我换一种输入方式的话:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO8AAABACAIAAAB9WLfVAAAD/ElEQVR4nO2cy3mrMBBGpyw1FJVhf7cB7VyFt1f7VOGNOnATZAECIY0eYGGS8X8W+exBDxaH8QBSaABACnT2CQDQDcZmojiYRtg424yIct03jVM9xPPQdLfbunTk3Nk/j5KmlCFqFnUpDJg9icNsdt9KPzb14HgadSG6kvp20eBR5JDZQTNNcrDZOpQ7p3h5kPRQ9ZIoXFopVds2Ye8UqWnvyjzfNDtooV4DVBNzlMiHfMlRHj+drqV7+fz74c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5ADbAZygM1ADrAZyAE2AznAZiCHH4gvG98VR4o+AAAAAElFTkSuQmCC" alt="" />

  当我用引号引起来的时候,发现又可以了。这里可以得出input()的特性为:在输入字符串的时候一定要带引号,数字可以不用。这个和raw_input()很不同,要注意一下。

  当然最后返回的依然是字符串类型。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfEAAABuCAIAAAC4F70IAAAQCElEQVR4nO2d24GsIAyGtxjLsRlrsRRLsRMr2IcZlUACwduMzve9nLOu3OE3Rsj+NS+6YZqmaZqGrjmPth9PLuGbeXfx2LfVSdt+NJO1/fi7fQoAEX9XFzg/PH5Y3OvJaDqSDgABl2s6bMDQ9NfzEUUHgAU0HQDgOaDpAADPYbem5z7f3RzLVd0Nng+dbT9u+CY6p9r2LRWeBx9MoI6/4KOl68tlrOEnafqqbXlxC+4r3bvc6qyvKd0uTe+GPStRK2J7T3dDMLDihz0EXZ9m1w2lfjaSr5eXq9bA7fnc7i+9kHqtV8VUrGrmk80mOIE/KR9tP5Yn4/ma3g2ySvYCqy7encAWZY+m77SuTtD0d3W6YRyPMPzafpwzSSdNN4zDkK2tkTxod9wFUfNFoV1f1zH1pSfp099WjI+/mbU5A/zFk+otZfLq66fIon8JQ9uPY98PiYWRWh3WnSWyM/o0TU8X9dyiYYifgrJJur22dp7skFYtLv0x7Xk/3TCNwzC+xnXs+/fTSqmSOu6uAoIqdcM0dDUDsyQX+aQiLmt2lEPCVbpkp6b7m7kmQNTBiWmnh5fDOajY6bPGBLbp+t81H/3OIt2Q0zAhoJ4snSsvqaFokWZlyRR2C9ff+DW9puYK3TCNfdePQ9cNr2ezrFpYWWvci/kHU2jotlmtURpZvPilsA/2uZI8pceH5dRZZ0/FKLm/mWEG+NTBh+1PXxdq1n5R9SC6mAp52fBYVoh/LufV36i/87ZiM1PRKbpurtX0tu3HcRz6VpHqSMi1cc/mrjzya3xcc/KlnpPyrigyFB8Fyg7DvaXnDkCrs05ejJL7mxnmh6aDj8T3svL+RaROOX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alMOuD6TVttNFZK5QXoc0COJ80Y+dXLO92350PTiqItgAAHw5f3qIxYwFm/G9iIgrqszukE47uaXptcFp0m4AALgXtqY7IyOmgW3jq56/KeTDSG5oelURaDoAPAHD9+K3051/lcJz0Y9MvkfT8b0AwJMwv5Ga/vQ0YEsU2LYR7u7Qya5c9GMn13JzaTrfSAHgYWT2Mhr7XpLPqXFg2yixDMKohbX1YidPg/qyZxEAfhFiAwAAPAc0HQDgOaDpAADPAU0HAHgOaDoAwHP4B3wWw1WiYKutAAAAAElFTkSuQmCC" alt="" />


  看到第一次输入后而报错的时候,有些人会问,如何我这里输入的是已经定义(也就是已经赋值)的变量名, 是不是就能够调用到在内存中的值了?

  在2.7(因为我只用过2.7,其他2.x不清楚)中,确实是可以这样的,但是在3.x中不行,因为这个功能被另一个内置函数 eval("name") 代替了("name"是传入字符串,然后用传入的字符串作为变量名)。

  当然input()的用户交互的功能还是有的,只是不能去调用变量了而已。


  但是,python2.7中也有一个 input() 函数,但这个 input() 函数又和 3.x 中的不一样,看代码示例:

num = input('---')
print type(num)

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJgAAAA2CAIAAAC0tsfoAAAC9UlEQVR4nO2bzZmzIBCApyxK2EqmDPN8DXDz9nXgdblbhRc6SBPugX8Eo0k0ZJz32YNOEAyv/ARcmKvcpegAbgCDCsEJk1OHGgCncIkY9SKBkPdC5jjN84TgjtUQStSjgA6gl3oupfn/YyLmL5S4focmQS9EB3BDlSR49x0Ov8WbsVdFOYtR28td4iRNkdwOVNLtZUL7fcooLFXuqfg7LJtu4A5f4l0ia9jnFJupJIXdogW3dYfPcbRI5iRYJBFYJBFYJBFYJBFYJBFYJBGOEVlZXTmJz5b+IQ4RqUdRXVraTmW9T49iuQL4/tK/jfeLfFjRuwhLpCGSrokeWfoX0fgYqWW/po3xNC5SYffti6AnURWJkPHz8zhSq3Qte7fj5KchE5pI6DlNJDZ3lyLaU7G7Q+kuiw12V2+4p7TI5TTyLoUR5j9y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j5F1XCuetvaGTLiCZfXuFu8ZvnzRXb3rZCujamNnA3yiOrZ2z28H9a6c4V59P4LGs57K7PH/NMyVi78vZyeOZOB5HY+rGMdkkgsECohWWjHwWSu6dcjeuQQ5mBKVUaGJPKnfsfIYLUi8d2GE8q/UVLv+fs/HgM5DQZecNkY9gr8aZTvd+6JS3JR+BvJNoH9G4fUTj9hGN20c0bp8/GCsfsOEvUT8AAAAASUVORK5CYII=" alt="" />

  可以看到在python2.7中,输入什么类型的就是什么类型的而和3.x中无论输入什么类型都是字符串的不同。

  最后总结:

    2.7中: input() 输入上面类型,得到的数据就是什么类型;而且不带引号的时候还能找到相应的变量

    3.x中: 无论 input() 输入的是什么,最终得到的都是字符串;而寻找变量的功能被 eval() 函数所替代。


  以上,就是用户交互的基本内容了,还有什么东西遗漏的话,我会继续补充。

4.python中的用户交互的更多相关文章

  1. Ant Design中根据用户交互展示不同的标签

    Ant Design中根据用户交互展示不同的标签 Ant Design使用的是React框架,那么我们先看代码: <Fragment> <a onClick={() => th ...

  2. python起源,变量,用户交互,流程语句

    1.Python的起源 Python是一门解释型弱类型编程语言. 特点:简单.明确.优雅 2.Python解释器 CPython官方提供的, 内部使用C语言来实现 PyPy,一次性把我们的代码解释成字 ...

  3. 1.3 Python基础知识 - 用户交互及传递参数

    一.用户交互 用户交互方面,每种开发语言都有不同的方式,例如shell语言用的是,“read -p "What is  your name ? " ”.python中是什么样子的呢 ...

  4. Python基础之用户交互、流程控制、循环语句

    python的简洁性真的令人叹为观止,没有JAVA那种输入还要导个包,不学不知道,一学吓一跳啊! 我在学这些基础的时候,会把python和java.c做对比,这样更好的理解记忆! 用户交互(输入) i ...

  5. python基础(4):用户交互、if判断、while循环、break和continue

    1. 用户交互 使⽤input()函数,可以让我们和计算机互动起来 语法: 内容 = input(提⽰信息) 这⾥可以直接获取到⽤户输入的内容 content = input("你吃了么?& ...

  6. python数据类型、用户交互和运算符

    基本数据类型 1.字典dict(dictionary) 能够准确的记录储存的信息 """ 大括号里面 放多个元素 之间用逗号隔开 元素为K:V键表示储存 K相对于V一般表 ...

  7. Python中接收用户的输入

    一.如何去接收用户的输入?使用函数 input() 函数 input() 让程序暂停运行,等待用户输入一些文本,获取用户的输入后,Python将其存储到一个变量中,以方便后期使用. name = in ...

  8. Python语法之用户交互与基本运算符

    一.与用户交互 1.接收用户输入 python3中的input会把用户输入的所有内容都存成str类型 age = input("请输入您的年龄: ") # "内容&quo ...

  9. python中的变量和算数运算

    先说下变量的作用: 用来保存数据,为什么要保存? 后面要使用. 变量的概念: 变量就是用来存储一些信息,供程序以后调用或者操作修改.变量为标记数据提供了一种描述性的名字,以便我们的程序可以被程序的阅读 ...

随机推荐

  1. ARM的QT phonon 的移植

    Phonon是QT提供的一套多媒体框架,提供多媒体播放图形界面和回放的功能,QT也是通过phonon来实现跨平台的多媒体播放.应用程序不需要关心多媒体播放到底是由什么实现的(如gstreamer.xi ...

  2. HDU 2209 翻纸牌游戏 状态BFS

    翻纸牌游戏 Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem De ...

  3. IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称

    微软给了我们一个很好的工具用来使IIS安全的运行-------UrlScan,下面是它的配置文件介绍 [options]UseAllowVerbs=1                ; 若为1,则使用 ...

  4. 001 The Hello World In Csharp

    C#是面向对象编程语言,语法和JAVA非常相似.接下来让我们看一下C#的Hello world. //001.cs using System; public class Hello { public ...

  5. 【Unity Shaders】学习笔记——SurfaceShader(二)两个结构体和CG类型

    [Unity Shaders]学习笔记——SurfaceShader(二)两个结构体和CG类型 转载请注明出处:http://www.cnblogs.com/-867259206/p/5596698. ...

  6. 自定义模板语言之simple_tag和自定义过滤器

    扩展你的模板系统 一般是扩展模板的tag和filter两个功能.可以用来创建你自己的tag和filter功能库. 创建模板库 分为两步: 1. 首先决定由模板库在哪一个注册的app下放置,你可以放在一 ...

  7. socket学习笔记——获取域名与IP(linux)

    gethostbyname.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #includ ...

  8. 学习练习 java编写西游记人物类

    package com.hanqi; public class XiYouJiRenWu { double height; String weapon; String name; void prine ...

  9. linux 将foo制定n, m之间行的内容, 追加到bar文件

    sed -ne '196, 207 p' foo >> bar;把文件foo 196-行207行的内容追加到 bar文件

  10. 动态链接库(dll) __declspec(dllimport) __declspec(dllexport)

    一. __declspec(dllexport) Microsoft 在 Visual C++ 的 16 位编译器版本中引入了 __export,使编译器得以自动生成导出名并将它们放到一个 .lib ...