日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

初识Python-1

發布時間:2023/11/30 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 初识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,注釋。


方便自己方便他人理解代碼。
單行注釋:#
多行注釋:'''被注釋內容''' """被注釋內容"""

msg = """ 今天我想寫首小詩, 歌頌我的同桌, 你看他那烏黑的短發, 好像一只炸毛雞。 """
#注釋被賦值

?

#-*- 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 條件:
結果

#第一種:if 4 > 5 :print('我請你喝酒') print('喝什么酒')#第二種: if 4 > 5:print('我請你喝酒') else:print('喝什么酒')#多選: num = input('請輸入您猜的數字:')if num == '1':print('一起抽煙') elif num == '2':print('一起喝酒') elif num == '3':print('新開了一家,走看看') else:print('你猜錯了.....')score = int(input("輸入分數:"))if score > 100:print("我擦,最高分才100...") elif score >= 90:print("A") elif score >= 60:print("C") elif score >= 80:print("B") elif score >= 40:print("D") else:print("太笨了...E")name = input('請輸入名字:') age = input('請輸入年齡:')if name == '小二':if age == '18':print(666)else:print(333) else:print('錯了....')

?

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 + 1

3,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/LXL616/p/10620875.html

總結

以上是生活随笔為你收集整理的初识Python-1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。