1. 程式人生 > >phyon快速入門(phyon基礎知識)

phyon快速入門(phyon基礎知識)

1、建立變數

a=10
b=2
c=a+b
print(c)

2、判斷語句

# coding=utf-8

a = 90

if a > 80:
    print("nice")
elif a > 60:
    print("normal")
else:
    print("bad")

***# coding=utf-8***用於指定中文的編碼格式 3、迴圈

# coding=utf-8

for i in range(1, 100):
    print("iterm {0},{1}".format(i, "hello"))

iterm是靜態的拼接字串,{1}、{0}就是需要動態輸入的字串。

4、函式定義

def hello():
    print("hello")

def max(a,b):
    if a > b:
        print(a)
    else:
        print (b)

hello()
max(2,3)

5、面向物件

# coding=utf-8

class hello:
    #建構函式
    def __init__(self,name):
       self._name=name

    def sayhello(self):
        print("hello {0}".format(self._name))

#繼承
class saybye(hello):
    def __init__(self, name):
        hello.__init__(self, name)

    def bye(self):
        print ("bye {0} ".format(self._name))

h=hello("zhangsan")
h.sayhello()

j=saybye("lisi")
j.bye()

6、匯入檔案

# import classdemo
#
# h=classdemo.saybye("lisi")
# h.bye()

from classdemo import  saybye

j=saybye("wangwu")
j.bye()

7、建立web2py專案 在這裡插入圖片描述 建立web2py在這裡插入圖片描述在這裡插入圖片描述建立完成後,右上角確定工程名稱,點選執行 在這裡插入圖片描述 設定埠號、管理員密碼,點選start server 在這裡插入圖片描述成功進入專案入口 直接生成了一個完整的web專案,甚至包括了登入註冊,很是方便

8、靜態檔案處理 在這裡插入圖片描述靜態檔案html、imag等都存放於static資料夾下,可以通過瀏覽器url直接訪問。 在這裡插入圖片描述直接訪問到檔案

9、編寫一個控制器(controller) 在web專案中新建一個main包,編寫一個hello.py的檔案

# coding=utf-8

def index():
   return " hello "