天天看點

python小知識_Python小知識

1_    python是一種解釋性語言,當程式運作時,一行一行的解釋,并運作;優點--調試代碼很友善,開發效率高,并且可以跨平台;不但入門容易,而且将來深入下去,可以編寫那些非常非常複雜的程式。缺點--運作速度慢。  python的種類:CPython   IPython   PyPy    Jython   IronPython

2_    變量:1.數字,字母,下劃線的任意組合,但是不能以數字開頭。

2.不能是Python中的關鍵字,不要用中文,不要用拼音。

3.駝峰法、下劃線

3_    基本資料類型:1數值型(int)   2字元串型(str)     3布爾型(bool)

字元串的拼接可以進行加法和乘法,

4_    if語句

if 條件:

語句

while循環

while 條件:

語句

如何跳出while循環:改變條件,跳出循環。

num = 0

flag=True

while flag:

num +=1

print(num)

if num==100:

flag=False

name = input("請輸入你的姓名:")

age = input("請輸入你的年齡:")

job = input("請輸入你的職業:")

hobby = input("請輸入你的愛好:")

msg='''

------------ info of %s -----------

Name  : %s

Age   : %s

job   : %s

Hobbie: %s

------------- end -----------------

'''%(name,name,age,job,hobby)

print(msg)

from django.shortcuts import render,redirect,HttpResponse

# Create your views here.

def login(request):

if request.method == "POST":

username = request.POST.get("username")

password = request.POST.get("password")

if username == "zhuyu" and password == "123456":

return redirect("http://www.baidu.com/")

else:

return HttpResponse("使用者密碼錯誤")

return render(request,"login.html")