python程序设计基础(三)
上次讲诉python的常见内置对象及其简单应用。和电脑进行交互也需要"沟通"。也就是说,你需要给电脑你的指令,然后,根据指令返回结果,得到你想知道的,所以今天讲述输入和输出。
输入。只需要input()内置函数,括号里可以填写提示用户输入的内容、格式等。
输出。输出要求不一样,对应输出方式也存在差异,总共来说有表达式语句、print()函数、文件输出、str.format()函数、repr()或str()。
表达式语句
一般在交互模式下,转换格式是使用。
Print()函数
print可以打印具体的变量也可以是变量名所对应的值。当输出对象有多个时,默认分隔符为空格,也可以根据需求更改。对象输出完成后,默认的为换行,也是可以更改的。
文件输出
文件输出后续详细讲诉。
repr()与str()
都将输出的值转化为字符串,不同的是str返回用户易读,而repr()返回解释器易读的形式。
邮政创新工作室实践项目"面邮优店":主打深夜泡面、代取快递等服务,面向重邮各寝室楼栋,超快速送达,让同学们体验到足不出楼就能吃到泡面,拿到快递的愉悦觉。
英文翻译
Last time I talked about the common built-in objects of python and their simple applications. Interaction with a computer also requires "communication." In other words, you need to give the computer your instructions, and then return the results according to the instructions, and get what you want to know, so today I will talk about input and output.
enter. Only the input() built-in function is required, and the content and format that prompt the user to input can be filled in the parentheses.
Output. The output requirements are different, and the corresponding output methods are also different. In total, there are expression statements, print() function, file output, str.format() function, repr() or str().
Expression statement, generally in interactive mode, the conversion format is used.
Print() function, print can print the specific variable or the value corresponding to the variable name.
When there are multiple output objects, the default separator is a space, which can also be changed according to requirements. After the object is output, the default is line break, which can also be changed.
The file output will be discussed in detail later.
str.format() function. Simple understanding is one-to-one correspondence. Parameter substitution, position substitution, keyword parameter substitution, or consistent use. Str indicates that the previous parameter is in the form of a string.
Both repr() and str() convert the output value into a string. The difference is that str returns a user-readable form, while repr() returns a form that is easy to read by the interpreter.
The postal innovation studio practice project "Mianyou Youdian": Mainly provides services such as late-night instant noodles and express delivery. It is delivered to the dormitories and buildings of Chongyu, so that students can experience it without leaving the building. Instant noodles, the pleasure of getting express delivery.
参考资料:菜鸟教程
翻译:Google翻译
本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。