初識Python

來源:互聯網
上載者:User

標籤:符號   儲存   開頭   文字   tin   第一個   首字母   int   安裝python   

1.什麼是電腦cpu:大腦3GHZ+記憶體:緩衝硬碟和CPU+硬碟:儲存資料的70MB/S讀寫的內容都是0 1代碼二進位2.程式設計語言簡單分類最早的是機器語言組合語言進階語言:c語言/python/java/c++/c#/object-c3.python是什麼程式設計語言編譯器:一次性編譯所有代碼,再執行解譯器:代碼逐行執行4.python分類1.python2有很多陋習2.python3更加清晰、簡單5.安裝pythonpython.org6.第一個python程式1.在命令列中編寫python代碼2.把程式寫在.py檔案中注意編碼7.變數程式運行過程中產生的值,臨時儲存在變數中,供後面的程式使用1.只能是字母、數字、底線2.不能數字開頭或全數字(強制規定)1=2print(1+1)3.不能是python的關鍵字 def if while4.不要用中文5.不要太長6.盡量有意義7.推薦使用:1)駝峰體(單字首大寫)2)底線(單詞用底線分開)    資料類型(初始)在python中每個變數都是有類型的1.整數(int)2.字串(str)字元:你能看見的單一文字元號空格算一個字元字串:一堆字元按照固定的順序排列(用‘ " ‘‘‘ """括起來)a=‘1‘b=‘1‘print(a+b)#11---------------------------------------------------------a="銀角大王"print(a*3)#銀角大王銀角大王銀角大王3.布爾(bool)對和錯,真和假True(真),False(假)8.常量不可變的變數,在python中沒有絕對的常量,大家約定俗成,所有的變數字母都用大寫就是常量PI = 3.141592653SYLAR_BIRTHDAY = 19919.列印語句print("12","13")a=10b=20print("a+b=", a+b)#3010.資料互動11.使用者互動input接收的內容是字串input(提示).會返給你輸入的內容name = input("請輸入你的名字")#程式會停在這裡,等待使用者輸入s = "我叫"+name+",今年18歲"print(s)12.條件判斷-ifmoney = 300#條件判斷if money > 500:print("打車回家")#if外面的東西print("回家")------------------------------------------------------------------------------------------------------------money = 300#條件判斷if money > 500:print("打車回家")else:#條件不成立的時候執行的內容print("坐公交")#if外面的東西print("回家")------------------------------------------------------------------------------------------------------------money = 5000if money > 3000:print("足療")elif money > 2000print("喝喝小酒")else:print("回家喝水")#足療、回家喝水13.迴圈語句-whilewhile True:print("123")#無限輸出123ctrl + c 停止-------------------------------------------------------------------------------------------------------------flag = Truecount = 0while flag:print("123")count = count + 1 #count會自增+=if count == 5flag = Flaseprint("吃飯")-------------------------------------------------------------------------------------------------------------數數:index = 1while index < 101:print(index)index = index+1-------------------------------------------------------------------------------------------------------------#1+2+3+4+5.......+99+100index = 1sum = 0while index < 101:sum= sum + indexindex = index + 1print(sum)14.break打斷迴圈,徹底停掉一個迴圈(停掉當前本冊迴圈)index = 1while index < 101:print(index)index = index + 1if index ==88break#停掉迴圈 8715.continue停止本次迴圈,繼續執行下一次迴圈index = 1while index < 101:if index ==88:index = index +1continueprint(index)index = index + 1--------------------------------------------------------------------------------------------------------------index = 1while index < 101:if index !=88:index = index +1continueprint(index)index = index + 1

 

初識Python

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.