python全栈开发内容_Python全栈开发之Day02
一. 回顧上節(jié)主要內(nèi)容
1. python是一門解釋型弱類型高級語言
2. python的解釋器
CPython, PyPy, JPython, IronPython, Ipython
3. print(內(nèi)容1, 內(nèi)容2)
4. 變量
程序運(yùn)行過程中產(chǎn)生的中間值, 暫時(shí)存儲在內(nèi)存中.供后面的程序使用
命名規(guī)范:
1. 由字母, 數(shù)字, 下戶線組成
2. 不能是數(shù)字開頭, 更不能是純數(shù)字
3. 不能使用關(guān)鍵字
4. 不要太長
5. 要有意義
6. 區(qū)分大小寫
7. 不要用中文
8. 推薦使用駝峰或下劃線
5. 類型
1. int整數(shù),
2. str字符串, ?',",''',"""
3. bool布爾. True, False
6. input() 用戶交互, 獲取的內(nèi)容是字符串類型
7. if語句
if 條件:
代碼塊
if 條件:
代碼塊
else:
代碼塊
if 條件:
代碼塊
elif 條件:
代碼塊
elif....
else:
代碼塊
if 條件:
if 條件:
...
else:
else:
二. 今日主要內(nèi)容
1. 循環(huán)
while 條件:
代碼塊(循環(huán)體)
else:
當(dāng)上面的條件為假. 才會(huì)執(zhí)行
執(zhí)行順序:
判斷條件是否為真. 如果真. 執(zhí)行循環(huán)體. 然后再次判斷條件....直到循環(huán)條件為假. 程序退出
2. break和continue
break: 停止當(dāng)前本層循環(huán)
continue: 停止當(dāng)前本次循環(huán). 繼續(xù)執(zhí)行下一次循環(huán)
3. 格式化輸出
%s 占位字符串
%d 占位數(shù)字
4. 運(yùn)算符
and: 并且, 兩端同時(shí)為真. 結(jié)果才能是真
or: 或者, 有一個(gè)是真. 結(jié)果就是真
not: 非真既假, 非假既真
順序: () => not => and => or
x or y:
如果x是零, 輸出y
如果x是非零, 輸出x
True: 非零
False: 零
5. 編碼
1. ascii. 最早的編碼. 至今還在使用. 8位一個(gè)字節(jié)(字符)
2. GBK. 國標(biāo)碼. 16位2個(gè)字節(jié).
3. unicode. 萬國碼. 32位4個(gè)字節(jié)
4. UTF-8. 可變長度的unicode.
英文: 8位. 1個(gè)字節(jié)
歐洲文字:16位. 2個(gè)字節(jié)
漢字. 24位. 3個(gè)字節(jié)
8bit = 1byte
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB
上接之前的02
03-while死循環(huán):
#死循環(huán)
count = 1
while count <= 5:print("噴死你..")
count= count + 1
#數(shù)數(shù) 1-100
count= 1
while count < 101:print(count)
count= count + 2
#讓用戶一直去輸入內(nèi)容, 并打印. 直到用戶輸入q的時(shí)候退出程序
whileTrue:
content= input("請輸入一句話,(輸入q退出程序):")if content == 'q':break #打斷. 終止當(dāng)前本層循環(huán)
print(content)
flag=Truewhileflag:
content= input("請輸入一句話,(輸入q退出程序):")if content == 'q':
flag= False #打斷. 終止當(dāng)前本層循環(huán)
print(content)else:print("123")whileTrue:
content= input("請輸入一句話,(輸入q退出程序):")if content == 'q':continue #停止當(dāng)前本次循環(huán). 繼續(xù)執(zhí)行下一次循環(huán)
print(content)
break和continue的區(qū)別: break是徹底的停止掉當(dāng)前層循環(huán). continue停止當(dāng)前本次循環(huán),繼續(xù)執(zhí)行下一次循環(huán)
count= 1
while count <= 10:if count == 4:
count= count + 1
continue #用來排除一些內(nèi)容
print(count)
count= count + 1
#必須要寫
count = 1
while count <= 20:if count == 10:break #不會(huì)觸發(fā)else的執(zhí)行, while...else...是一個(gè)整體. break的時(shí)候徹底的停止這個(gè)整體
print(count)
count= count + 1
else: #當(dāng)上面的條件不成立的時(shí)候執(zhí)行這個(gè)else中的代碼
print("數(shù)完了")
04-格式化輸出:
name="alex"age= 38hobby= "浪"location= "湖邊"
#print(age+"歲的"+name+"在"+location+"喜歡"+hobby) ##格式化#%s 占位. 占位的是字符串, 全能的. 什么都能接#%d 占位. 占位的是數(shù)字
print("%s歲的%s在%s喜歡%s" %(age, name, location, hobby))
name= input("請輸入名字:")
age= input("請輸入年齡:")
job= input("請輸入你的工作:")
hobby= input("請輸入你的愛好:")#s = '''------------ info of %s -----------#Name : %s#Age : %s#job : %s#Hobbie: %s#------------- end -----------------''' % (name, name, age, job, hobby)
print(s)
name= 'sylar'
#如果你的字符串中出現(xiàn)了%s這樣的格式化的內(nèi)容. 后面的%都認(rèn)為是格式化.如果想要使用%. 需要轉(zhuǎn)義 %%
print("我叫%s, 我已經(jīng)學(xué)習(xí)了2%%的python了" %(name))print("我叫周潤發(fā). 我已經(jīng)活了50%了")
05-簡單基本運(yùn)算:
print(1+1)print(1-1)print(1*2)print(1/2)print(10%3) #計(jì)算余數(shù) 10/3=3......1
n= 49
if n % 2 == 1:print("奇數(shù)")else:print("偶數(shù)")print(10//3) #整除. 地板除. 計(jì)算商
print(5**3) #5的2次冪 m**n m的n次冪
a= 10b= 20
print(a == b) #等于
print(a != b) #不等于
a= 1b= 2a+= b #a = 3 a+=b => a = a + b#a *= b => a = a * b
print(a)print(b)
06-邏輯運(yùn)算:
#1. and 并且的含義. 左右兩端同時(shí)為真. 結(jié)果才能是真.#2. or 或者的含義. 左右兩端有一個(gè)是真. 結(jié)果就是真. 所有的條件都是假. 結(jié)果才是假#3. not 取反 非真既假, 非假既真#順序: () => not => and => or 相同的運(yùn)算. 從左往右算
print(1>2 and 4<6 or 5>7)print(1 > 2 or 3 > 4)print(5>3 or 4<6)print(5>3 or 4>6)print(3>4 or 4<3 and 1==1) #False
print(1 < 2 and 3 < 4 or 1>2 ) #True
print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) #True
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) #False
print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) #False
print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) #False
xory 如果x是0 返回y, 如果x是非零, 返回xprint(1 or 2) #1
print(1 or 0) #1
print(0 or 1) #1
print(0 or 2) #2
print(0 or 1 or 2 or 3)print(3 or 0 or 1 or 0 or 2)
and和or相反. 不要去總結(jié)and. 記住orprint(1 and 2) #2
print(0 and 2) #0
print(1 and 0) #0
print(0 and 1) #0
print(1 and 2 or 3)print(1 or 2 and 3)
False: 0, True:1(非零)print(1 and 2>3)print(2>3 and 1)print(1 > 2 or 0 and 3 < 6 or 5) #先算and 后算or
print(2**32)
07-in和not in:
content = input("請輸入你的評論:")if "馬化騰" not incontent:print("你的言論不和諧")else:print(content)
總結(jié)
以上是生活随笔為你收集整理的python全栈开发内容_Python全栈开发之Day02的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 叉车多少钱一个啊?
- 下一篇: 分解 python_面试官:如何用Pyt