1,格式化輸出,%s? %d
2,復習昨日講題
編譯型:
將代碼一次性全部編譯成二進制,然后運行。
優點:執行效率高。
缺點:開發效率低,不能跨平臺。
C
解釋型:
代碼逐行解釋,邊解釋邊執行。
優點:開發效率高,可以跨平臺。
缺點:執行效率低。
python
變量:
1,必須由數字字母下劃線任意組合。
2, 數字不能開頭。
3,不能是Python中的關鍵字。
4,不能是中文。
5,不能太長。
6,要具有可描述性。
常量:不能改變的量,全部大寫的變量為常量,放在文件起始。
基礎數據類型:
int :運算。
str:
被引號引起來的都是字符串。
+ 拼接。str + str
* str * int。
bool
True,False
用戶輸入:input
python2x: raw_input()
input() 相當于eval()
python3x: input()
if
if 條件:
pass
if 條件:
pass
else:
pass
if 條件:
pass
elif 條件:
pass
elif 條件:
pass
if 條件:
pass
elif 條件:
pass
elif 條件:
pass
else:
pass
if 條件:
if ...
else:
pass
else:
if..
else:...
while 條件:
pass
break:直接跳出當前循環。
continue:結束本次循環,繼續下一次循環。
3,while else
6,講解昨天作業上6道題
'''
1、使用while循環輸入 1 2 3 4 5 6 8 9 10
2、求1-100的所有數的和
3、輸出 1-100 內的所有奇數
4、輸出 1-100 內的所有偶數
5、求1-2+3-4+5 ... 99的所有數的和
6、用戶登陸(三次機會重試)
'''
# 1、使用while循環輸入 1 2 3 4 5 6 8 9 10
# count = 1
# while count < 11:
# if count == 7:
# count += 1
# print(count)
# count += 1
# 5、求1-2+3-4+5 ... 99的所有數的和
# sum = 0
# count = 1
# while count < 100:
# if count % 2 == 0:
# sum = sum - count
# else:
# sum = sum + count
# count += 1
# print(sum)
# 6、用戶登陸(三次機會重試)
# i = 0
# while i < 3:
# username = input('請輸入用戶名:')
# password = input('請輸入密碼:')
# if username == '婉容' and password == '123':
# print('登錄成功')
# break
# else:
# print('用戶名或者密碼錯誤,請重新輸入')
# i += 1
4,運算符
# print(2 > 1 and 3 < 4 or 8 < 10 and 4 > 5)
# 第一種情況 邏輯運算符前后都是比較運算
# 優先級概念:() > not > and > or,同一優先級從左至右以此計算。
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
# print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
# 第二種情況 邏輯運算符前后都是數字
'''
x or y if x True,return x,else y
'''
# print(3 or 5)
# print(2 or 5)
# print(0 or 5)
# print(-4 or 5)
# print(3 and 5)
# print(1 or 3 or 4 or 0)
# print(1 or 3 or 0)
# print(1 > 2 and 3 or 4)
'''
數字與bool值轉化
int ---> bool 非零 True ,零 False
bool---> int True 1, False 0,
'''
# print(bool(100))
# print(bool(0))
7,格式化輸出
# name = input('請輸入名字:')
# age = input('請輸入年齡:')
# sex = input('請輸入性別:')
#
# msg = '我的名字是' + name + '我的年齡是' + age + '我的性別是' + sex
# print(msg)
msg = '''
------------ info of Alex Li -----------
Name : Alex Li
Age : 22
job : Teacher
Hobbie: girl
------------- end -----------------
'''
# 格式化輸出 %占位符 s d
# name = input('請輸入姓名:')
# age = int(input('請輸入年齡:'))
# job = input('請輸入工作:')
# hobby=input('請輸入愛好:')
#
# msg = '''
# ------------ info of %s -----------
# Name : %s
# Age : %d
# job : %s
# Hobbie: %s
# ------------- end -----------------
# ''' % (name, name, age, job, hobby)
# print(msg)
#第二種使用方法
# dic = {
# 'name':'老男孩',
# 'age':58,
# 'job':'boss',
# 'hobby':'money',
# }
# msg = '''
# ------------ info of %(name)s -----------
# Name : %(name)s
# Age : %(age)d
# job : %(job)s
# Hobbie: %(hobby)s
# ------------- end -----------------
# ''' % dic
# print(msg)
# 格式化輸出,在格式化輸出中,單純的表示% 需要用%% 去表示。
# msg = '我叫%s,今年%s,學習進度2%%' % ('爽妹兒','18')
# print(msg)
#while else 當while循環被break打斷,則不走else程序。
# count = 0
# while count <= 5:
# count += 1
# print("Loop",count)
# if count == 4: break
#
# else:
# print("循環正常執行完啦")
# print("-----out of while loop ------")
5,編碼初始
諜戰片:嘀嘀嘀 滴滴 高低電平,0101010
電腦文件的存儲,與文件的傳輸 010101010
初級密碼本 :ascii 字母,數字,特殊字符。
0000 0001 8位== 1個字節 一個字節表示一個字符。
字符:組成內容的最小單元。 abc a b c
中國 中 國
a 01100001
b 01100010
c 01100011
萬國碼:unicode
創建初期 16位 兩個字節表示一個字符。
a :01100001 01100001
中:01100011 01100001
升級:32位 四個字節表示一個字符。
a :01100001 01100001 01100001 01100001
中:01100011 01100001 01100011 01100001
資源浪費。
對Unicode升級 :utf-8。
utf-8:最少用8位數去表示一個字符。
a:01100001(字母用1個字節表示。)
歐洲文字:01100001 01100001(歐洲用2個字節表示。)
亞洲文字——中:01100001 01100001 01100001 (歐洲用3個字節表示。)
utf-16:最少用16位數去表示一個字符
gbk:國家標準。
a : 01100001
中: 01100001 01100001
8位 1個byte
1024bytes 1kb
1024kb 1MB
1024MB 1GB
1024GB 1TB