標籤:不能 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基礎一