Python input()
生活随笔
收集整理的這篇文章主要介紹了
Python input()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在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:
轉載于:https://www.cnblogs.com/OliverQin/p/6076501.html
總結
以上是生活随笔為你收集整理的Python input()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java的单例设计模式
- 下一篇: Python进阶03 模块