Python基礎一

來源:互聯網
上載者:User

標籤:不能   from   global   劃線   logs   put   rom   ict   int   

一、介紹

python部分以python3為基礎進行闡述

print("Hello World!")

二、變數

python沒有常量的概念,一切皆可以是變數,但習慣性的用全大寫字母組成的字元代表常量,AGE_OF_RAP = 56

變數是指可變化的量,可用來代指記憶體裡某個地址中儲存的內容。有如下規則:

1.變數名只能是 字母、數字或底線的任意組合

2.變數名的第一個字元不能是數字

3.以下關鍵字不能聲明為變數名[‘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‘]

三、字串

字串是python基礎資料類型之一,由單引號或雙引號組成,如‘i love python‘或"i love python",具有不可變性,因此一旦建立便不能修改

四、讀取使用者輸入

python3棄用了raw_input(),只用input()進行讀取使用者的輸入

name = input("What is your name?")

五、列表

重要的基礎資料型別 (Elementary Data Type)之一

list1 = [‘physics‘, ‘chemistry‘, 1997, 2000]list2 = [1, 2, 3, 4, 5 ]list3 = ["a", "b", "c", "d"]

六、字典

重要的基礎資料型別 (Elementary Data Type)之一

dict1 = { ‘abc‘: 456 }dict2 = { ‘abc‘: 123, 98.6: 37 }

七、流程式控制制

x = int(input("請輸入您的總分:"))if x >= 90:    print(‘優‘)elif x>=80:    print(‘良‘)elif x >= 70:    print(‘中‘)elif x >= 60:    print(‘合格‘)else:    print(‘不合格‘)

八、迴圈

#!/usr/bin/python count = 0while count < 9:   print ‘The count is:‘, count   count = count + 1 print "Good bye!"

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.