初识Python-1
1,計(jì)算機(jī)基礎(chǔ)。
2,python歷史。
宏觀上:python2 與 python3 區(qū)別:
python2 源碼不標(biāo)準(zhǔn),混亂,重復(fù)代碼太多,
python3 統(tǒng)一 標(biāo)準(zhǔn),去除重復(fù)代碼。
3,python的環(huán)境。
編譯型:一次性將所有程序編譯成二進(jìn)制文件。
缺點(diǎn):開發(fā)效率低,不能跨平臺。
優(yōu)點(diǎn):運(yùn)行速度快。
:C,C++等等。
解釋型:當(dāng)程序執(zhí)行時(shí),一行一行的解釋。
優(yōu)點(diǎn):開發(fā)效率高,可以跨平臺。
缺點(diǎn):運(yùn)行速度慢。
:python ,php,等等。
4,python的發(fā)展。
5,python種類。
運(yùn)行第一個(gè)py文件:
python3x :python 文件路徑 回車
python2x :python2 文件路徑 回車
python2 python3 區(qū)別:python2默認(rèn)編碼方式是ascii碼
解決方式:在文件的首行:#-*- encoding:utf-8 -*-
python3 默認(rèn)編碼方式utf-8
6,變量。
變量:就是將一些運(yùn)算的中間結(jié)果暫存到內(nèi)存中,以便后續(xù)代碼調(diào)用。
1,必須由數(shù)字,字母,下劃線任意組合,且不能數(shù)字開頭。
2,不能是python中的關(guān)鍵字。
['and', 'as', 'assert', 'break', 'class', 'continue',
'def', 'del', 'elif', 'else', 'except', 'exec',
'finally', 'for', 'from', 'global', 'if', 'import',
'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',
'raise', 'return', 'try', 'while', 'with', 'yield']
3,變量具有可描述性。
4,不能是中文。
7,常量。
一直不變的量。 π
BIR_OF_CHINA = 1949
8,注釋。
方便自己方便他人理解代碼。
單行注釋:#
多行注釋:'''被注釋內(nèi)容''' """被注釋內(nèi)容"""
#注釋被賦值
?
#-*- encoding:utf-8 -*- #print('我愛中國')?
9,用戶交互。input
1,等待輸入,
2,將你輸入的內(nèi)容賦值給了前面變量。
3,input出來的數(shù)據(jù)類型全部是str
?
name = input('請輸入你的名字:') age = input('請輸入你的年齡:') print('我的名字是'+name,'我的年齡'+age+'歲')?
10,基礎(chǔ)數(shù)據(jù)類型初始。
數(shù)字:int 12,3,45
+ - * / **
% 取余數(shù)
ps:type()
字符串轉(zhuǎn)化成數(shù)字:int(str) 條件:str必須是數(shù)字組成的。
數(shù)字轉(zhuǎn)化成字符串:str(int)
字符串:str,python當(dāng)中凡是用引號引起來的都是字符串。
可相加:字符串的拼接。
可相乘:str * int
bool:布爾值。 True False。
11,if。
if 條件:
結(jié)果
?
12,while。
while 條件:
循環(huán)體
無限循環(huán)。
終止循環(huán):
1,改變條件,使其不成立。
print('111') while True:print('我們不一樣')print('在人間')print('癢') print('222')#從1--100 count = 1 flag = True #標(biāo)志位 while flag:print(count)count = count + 1if count > 100 :flag = Falsecount = 1 while count <= 100:print(count)count = count + 1count = 1 sum = 0while count <= 100:sum = sum + count count = count + 1print(sum)2,break
print('11') while True:print('222')print(333)breakprint(444) print('abc')count = 1 while True:print(count)count = count + 1if count > 100:breakprint(111) count = 1 while count < 20 :print(count)continuecount = count + 13,continue
count = 0 while count <= 100 : count += 1if count > 5 and count < 95: continue print("loop ", count)print("-----out of while loop ------")?
?
- 太白金星老師
- 博客:https://www.cnblogs.com/jin-xin/
別人能做的事,你能做的更好。
轉(zhuǎn)載于:https://www.cnblogs.com/LXL616/p/10620875.html
總結(jié)
以上是生活随笔為你收集整理的初识Python-1的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 子宫腺肌症人会瘦吗
- 下一篇: 利用layui前端框架实现对不同文件夹的