在Python语言中,我们经常需要与用户实现交互,下面是一个小实例

# -*- coding:UTF-8 -*-
#获取输入参数,并将输入的值存储到txt文件中
String1 = input("Enter The Value of String1:")
String2 = input("Enter The Value of String2:")
f = open(r'D:\python\File\Pra_Q.txt','w') try:
f.write(String1)
f.write('\n')
f.write(String2) finally:
f.close()

上述代码实现功能为:用户输入2个字符串,然后将这两个字符串存储到文件Pra_Q.txt中

执行结果:

在Python 3.5.2中raw_input()变成了input()

>>> raw_input_A=raw_input("Enter the var:")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'raw_input' is not defined
>>> raw_input_A=input("Enter the var:")
Enter the var:

  

Python input()的更多相关文章

  1. Python input 和 raw_input的区别

    转载[http://www.pythonclub.org/python-basic/input] 使用input 和 raw_input 都可以读取控制台的输入,但是input和raw_input在处 ...

  2. 【每日一个小技巧】Python | input的提示信息换行输出,提示信息用变量表示

    [每日一个小技巧]Python | input的提示信息换行输出,提示信息用变量表示 在书写代码的途中,经常会实现这样功能: 请输入下列选项前的序号: 1.选择1 2.选择2 3.选择3 在pytho ...

  3. Python input 使用

    Python 3.0 中使用"input" , Python 2.0 中使用"raw_input"Python 3.5: #!C:\Program Files\ ...

  4. python input() 与 raw_input()

    使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时: input返回的是数值类型,如int,floatraw_inpo ...

  5. python input选择

    例1 import sys #声明字符串数组并初始化 newspaper=['1.北京晚报','2.作家文摘','3.参考消息', \ '4.证券报','5.不需要'] #字符串数组的输出 ): pr ...

  6. python input 与raw_input函数的区别

    转自:http://blog.csdn.net/sruru/article/details/7790436 以前没有深入考虑过raw_input与input函数的区别,所以一直比较困惑,今天测试之后, ...

  7. nyoj 259-茵茵的第一课 (python, input, print)

    259-茵茵的第一课 内存限制:64MB 时间限制:3000ms 特判: No 通过数:23 提交数:36 难度:0 题目描述: 茵茵今年已经六年级了,爸爸给她报了一个学习程序设计的班. 第一节课上, ...

  8. Python input() 函数

    Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...

  9. Python input/output boilerplate for competitive programming

    The following code is my submission for Codeforces 1244C The Football Season. import io import sys i ...

随机推荐

  1. Orchard官方文档翻译(四) 让Orchard在WebMatrix下工作

    原文地址:http://docs.orchardproject.net/Documentation/Working-with-Orchard-in-WebMatrix 想要查看文档目录请用力点击这里 ...

  2. 003.ASP.NET MVC集中管理Session

    原文链接:http://www.codeproject.com/Tips/790387/Session-in-ASP-NET-MVC 1.前言 今天有得有失啊,看到这篇,专心记下里面的精华吧 2.一般 ...

  3. cocos2d-x Android版游戏之中国移动SDK嵌入

    . 拷贝API 将SDK\runtime\CMBilling20007.jar拷贝至游戏工程的runtime目录下(或其他目录) ,但切记不能放在libs目录下编译,否则编译报错(如:bad rang ...

  4. socket学习笔记——并发服务器与I/O程序分割客户端

    client.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <u ...

  5. X86 架构和 ARM 架构

    1.关于x86架构 X86是一个intel通用计算机系列的标准编号缩写,也标识一套通用的计算机指令集合,X86是由Intel推出的一种复杂指令集,用于控制芯片的运行的程序,现在X86已经广泛运用到了家 ...

  6. mysql 二进制安装文件 下载

    在linuex环境下安装mysql,二进制安装包是最合适的方式,下载下来不用编译就可用了. 官方说明文档:http://dev.mysql.com/doc/refman/5.1/en/binary-i ...

  7. MVC ckeditor的基本使用

    之前在自己的WebForm练习项目里面用到过ckeditor,时隔蛮久后,今天再一次把ckeditor运用到MVC里面,用于最近着手开发的企业站的新闻动态的内容之新增与修改. 找到的资料都说要把下载的 ...

  8. prototype原型模式中的问题

    对于每个构造函数来说,都有一个prototype属性.对于每个对象实例来说,都有_proto_属性. 参看下面代码: function Person(){} Person.prototype={ na ...

  9. sqlplus sys/system@'(description=(address_list=(address=(protocol=tcp)(host=192.168.11.199)(port=1521)))(connect_data=(service_name=byRuiy)))' as sysdba

  10. Dynamics AX 4.0 多表looup

    project rar:http://files.cnblogs.com/files/sxypeace/PrivateProject_MutilTableLookupOnCtronl.rar 在AX ...