初识Python-1
1,計算機基礎。
2,python歷史。
宏觀上:python2 與 python3 區別:
python2 源碼不標準,混亂,重復代碼太多,
python3 統一 標準,去除重復代碼。
3,python的環境。
編譯型:一次性將所有程序編譯成二進制文件。
缺點:開發效率低,不能跨平臺。
優點:運行速度快。
:C,C++等等。
解釋型:當程序執行時,一行一行的解釋。
優點:開發效率高,可以跨平臺。
缺點:運行速度慢。
:python ,php,等等。
4,python的發展。
5,python種類。
運行第一個py文件:
python3x :python 文件路徑 回車
python2x :python2 文件路徑 回車
python2 python3 區別:python2默認編碼方式是ascii碼
解決方式:在文件的首行:#-*- encoding:utf-8 -*-
python3 默認編碼方式utf-8
6,變量。
變量:就是將一些運算的中間結果暫存到內存中,以便后續代碼調用。
1,必須由數字,字母,下劃線任意組合,且不能數字開頭。
2,不能是python中的關鍵字。
['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,注釋。
方便自己方便他人理解代碼。
單行注釋:#
多行注釋:'''被注釋內容''' """被注釋內容"""
#注釋被賦值
?
#-*- encoding:utf-8 -*- #print('我愛中國')?
9,用戶交互。input
1,等待輸入,
2,將你輸入的內容賦值給了前面變量。
3,input出來的數據類型全部是str
?
name = input('請輸入你的名字:') age = input('請輸入你的年齡:') print('我的名字是'+name,'我的年齡'+age+'歲')?
10,基礎數據類型初始。
數字:int 12,3,45
+ - * / **
% 取余數
ps:type()
字符串轉化成數字:int(str) 條件:str必須是數字組成的。
數字轉化成字符串:str(int)
字符串:str,python當中凡是用引號引起來的都是字符串。
可相加:字符串的拼接。
可相乘:str * int
bool:布爾值。 True False。
11,if。
if 條件:
結果
?
12,while。
while 條件:
循環體
無限循環。
終止循環:
1,改變條件,使其不成立。
print('111') while True:print('我們不一樣')print('在人間')print('癢') print('222')#從1--100 count = 1 flag = True #標志位 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/
別人能做的事,你能做的更好。
轉載于:https://www.cnblogs.com/LXL616/p/10620875.html
總結
以上是生活随笔為你收集整理的初识Python-1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 子宫腺肌症人会瘦吗
- 下一篇: python数据分析常用包之Scipy