raw_input和input兩個都是 python 的內建函數,透過讀取控制台的輸入與使用者實現互動。但他們的功能不盡相同。以下舉出兩個例子,來說明兩者使用上的差異。
範例1
Python 2.7.5 (default, Nov 18 2015, 16:26:36) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> raw_input_A = raw_input("raw_input: ") raw_input: PythonTab.com >>> print raw_input_A PythonTab.com >>> input_A = input("Input: ") Input: PythonTab.com Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> NameError: name 'PythonTab' is not defined >>> >>> input_A = input("Input: ") Input: "PythonTab.com" >>> print input_A PythonTab.com >>>
範例2
Python 2.7.5 (default, Nov 18 2015, 16:26:36) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> raw_input_B = raw_input("raw_input: ") raw_input: 2015 >>> type(raw_input_B) <type 'str'> >>> input_B = input("input: ") input: 2015 >>> type(input_B) <type 'int'> >>>
範例 1 可以看到:這兩個函數都可以接收 字串 ,但 raw_input() 直接讀取控制台的輸入(任何類型的輸入它都可以接收)。而對於 input() ,它希望能夠讀取一個合法的 python 表達式,即你輸入字串的時候必須使用引號將它括起來,否則它會引發一個 SyntaxError 。
範例 2 可以看到:raw_input() 將所有輸入當作字串看待,傳回字串類型。而input() 在對待純數字輸入時具有自己的特性,它返回所輸入的數字的類型( int, float );同時在例子1 知道,input() 可接受合法的python 表達式,舉例:input( 1 + 3 ) 會傳回int 型的4 。
查看python手冊,得知:
input([prompt])
Equivalent to eval(raw_input(prompt))
input() 本質上還是使用它之後再呼叫eval() 函數,所以,你甚至可以將表達式作為input() 的參數,並且它會計算表達式的值並傳回它。
不過在Built-in Functions 裡有一句話是這樣寫的:Consider using the raw_input() function for general input from users..
除非對input() 有特別需要,否則一般情況下我們都是推薦使用
除非對input() 有特別需要,否則一般情況下我們都是推薦使用

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

WebStorm Mac版
好用的JavaScript開發工具