Python input()
生活随笔
收集整理的這篇文章主要介紹了
Python input()
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在Python語(yǔ)言中,我們經(jīng)常需要與用戶實(shí)現(xiàn)交互,下面是一個(gè)小實(shí)例
# -*- coding:UTF-8 -*- #獲取輸入?yún)?shù),并將輸入的值存儲(chǔ)到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()上述代碼實(shí)現(xiàn)功能為:用戶輸入2個(gè)字符串,然后將這兩個(gè)字符串存儲(chǔ)到文件Pra_Q.txt中
執(zhí)行結(jié)果:
在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:
轉(zhuǎn)載于:https://www.cnblogs.com/OliverQin/p/6076501.html
總結(jié)
以上是生活随笔為你收集整理的Python input()的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java的单例设计模式
- 下一篇: 9.0 C++远征:对象成员