一、安裝Python34
Windows
在Python官網(https://www.python.org/downloads/)下載安裝套件並安裝。
Python的預設安裝路徑是:C:\Python34
配置環境變數:【右鍵計算機】--》【屬性】--》【進階系統設定】--》【高級】--》【環境變數】--》【在第二個內容方塊中找到變數名稱為Path 的一行,雙擊】 --> 【Python安裝目錄追加到變值值中,用;分割】
二、第一個Python程式
1. 在互動器中執行: 直接呼叫python自帶的交互器運行程式碼(用於暫時偵錯)
2.把程式寫在檔案裡執行
(1)安裝PyCharm(http://www.jetbrains.com/pycharm/download/)
(2 )新建一個project和Python File
(3)寫入程式碼
Print("Hello World!")
(4)運行
三、定義變數
##變數在程式中用來儲存和調用。變數相當於一個儲存資料的容器,把資料存在記憶體中。 (內存和硬碟的區別:內存比硬碟快,內存是臨時存儲,硬碟是永久存儲)#!/user/bin/env python# -*-coding:utf-8 -*- user_name = "Grace" #申明一个字符串变量 age = 21 #申明一个数字变量變量定義的規則:
1.單引號,雙引號,三引號都是字符字串
2.變數應該具有實際意義,能讓人更加明了
3.變數名稱只能是字母,數字,底線的任意組合
4.變數名稱的第一個字元不能是數字
5.不能用關鍵字申明變數名稱
其最多只能用 8 位元來表示(一個位元組),即:2**8 = 256-1,所以,ASCII碼最多只能表示255 個符號。
2. 顯然ASCII碼無法將世界上的各種文字和符號全部表示,所以,就需要新出一種可以代表所有字元和符號的編碼,即:Unicode
Unicode(統一碼、萬國碼、單碼)是一種在電腦上使用的字元編碼。 Unicode 是為了解決傳統的字元編碼方案的局限而產生的,它為每種語言中的每個字元設定了統一並
且唯一的二進位編碼,規定雖有的字元和符號最少由 16 位來表示(2個位元組),即:2 **16 = 65536,
註:此處說的是最少2個字節,可能更多
3. UTF-8,是對Unicode編碼的壓縮和優化,他不再使用最少使用2個字節,而是將所有的字符和符號進行分類:ascii碼中的內容用1個字節保存、歐洲的字符用2個字節保存,
東亞的字元用3個位元組保存...
Python2點幾的版本預設ascill, 可以指定一個字元集:
#!/usr/bin/env python # -*- coding: utf-8 -*- print "你好,世界"五、註解
單行注視:# 被註解內容
多行註解:''' 被註解內容 '''('''代表多行字串,多行字串直接放在Python中,會被Python忽略)
六、格式化字串
1. 在Python3裡 input 預設接收的都是字串
name = input("input your name:") age = int(input("input your age:")) #convert str to int job = input("input your job:") message=''' Information of user %s: _______________________ name: %s age: %f job: %s ---------End----------- ''' %(name,name,age,job) print(message)七、表達式if... else用一個登入驗證來說明:
rightName = "tt" password = "wpl" userName = input("Please enter your name:") userPassword = input("Please enter your password:") #Python 是一个强制缩进语言,通过缩进来控制从属关系 if userName == rightName and userPassword == password: print("Welcome login ...") else: print("your user name or user password is invalid")用一個猜年齡的程式說明:
需求:
一直猜錯的情況下一共可猜8次
每猜錯3次提示用戶是否繼續,用戶輸入 Y 表示繼續,輸入其它任何字符退出程序
用戶猜對就結束程序
age = 22
count = 0
for i in range(10):
print("-->counter",count)
if count guess_age = int( input("Please input age:") )
if guess_age == age:
print("You are right")
break
elif guess_age > age:
print("Think smaller!")
else:
print("Think bigger...")
count += 1
else:
user_answer = input("Do you want countine:")
if user_answer == "Y":
count = 0
else:
print("bye")
break
该段代码最多进行了10次循环,有两次循环是询问用户是否继续猜,在用户回答为Y时,并没有在该次循环让用户猜年龄。
而是进入下一个循环后才开始猜年龄。
九、模块初识
import sys print(sys.path) #打印python的环境变量地址 导入sys模块, 调用该模块中的path数据。 注意: 标准库一般放在 <python>\\lib 第三方库一般放在 <python>\\lib\\site-packages (自己写的python文件放到该目录,编写其它模块时就可以导入该文件,并调用方法与数据) os模块的几个方法: import os os.system("dir") #执行系统命令,只打印出命令结果,不会保存(当前路径下的目录) cmd_res = os.popen("dir") #执行命令并把结果保存到一个文件中 print(cmd_res.read()) #读取这个文件并打印出结果 os.mkdir("other_dir") #在当前路径下创建一个新目录</python></python>
以上是Python學習基礎One的使用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

Inpython,ListSusedynamicMemoryAllocationWithOver-Asalose,而alenumpyArraySallaySallocateFixedMemory.1)listssallocatemoremoremoremorythanneededinentientary上,respizeTized.2)numpyarsallaysallaysallocateAllocateAllocateAlcocateExactMemoryForements,OfferingPrediCtableSageButlessemageButlesseflextlessibility。

Inpython,YouCansspecthedatatAtatatPeyFelemereModeRernSpant.1)Usenpynernrump.1)Usenpynyp.dloatp.dloatp.ploatm64,formor professisconsiscontrolatatypes。

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,減法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

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

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver CS6
視覺化網頁開發工具