วันจันทร์ที่ 15 สิงหาคม พ.ศ. 2559

Basic Python

ทบทวน Python

def setup():
    a = [-1,-2,3,5,8,4,10]
    print(calc_postive_sum(a))


def calc_postive_sum(a):
    sum = 0
    for i in a:
        if(i > 0):
            sum+=i
     
    return sum

setup()


การใช้ Class

class Person:
    def __init__(self,name,age):
        self.name=name
        self.age=age
    def display(self):
        print("Name:",self.name)
        print("Age:",self.age)

def setup():
    person1 = Person("John",20)
    person2 = Person("Jan",19)
    people = [person1,person2]
    for i in people:
        i.display()
setup()
     


built-in data structure
List


Sets
def setup():
   a = [5,2,3,5,5,6,8,6,5,2]
   a = remove_duplicate(a)
   print(a)
   
def remove_duplicate(a):
   return list(set(a))
setup()


ไม่มีความคิดเห็น:

แสดงความคิดเห็น

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...