Skip to content

Arisa-Kaewsuan/Python_Tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python   Python

  •   Python ใช้ทำอะไรได้บ้าง ?

     1. ใช้ทำโปรแกรมแบบมี GUI : ใช้ library เช่น Tkinter , PyGTK , PyQT , JPython , Kivy , wxPython , ... 2. ใช้ทำเกม : ใช้ library เช่น pygame 3. ใช้ในงานสาย Data Science : ใช้ library เช่น pandas , Numpy , seaborn , mathplotlib 4. ใช้ในงานสาย IoT (Internet of Thing) : Arduino , ทำ Robot , Raspberry pi 5. ใช้ทำ web : ใช้ library เช่น Django , Flask 
  •   เริ่มใช้ Python ยังไง ?

     1. install python : คือ โปรแกรมแปลภาษาไพธอนเป็นภาษาเครื่อง เราก็จะสามารถเขียนไพธอนด้วย editor/IDE แล้วรันดูผลลัพธ์ได้ 2. install editor : มีให้เลือกใช้เยอะมาก เช่น vscode (นิยมใช้สำหรับผู้เริ่มต้น), pycharm , Google colab (นิยมใช้สำหรับผู้เริ่มต้น สะดวกมากใช้บนเว็บได้เลย แค่มีบัญชี Google ), sublimetext (สำหรับคนใช้ mac) , Jupyter (นิยมใช้ในงาน data science) , Spyder (อาจารย์ชอบใช้สอนตามมหาลัยสาย data science ทำ ML) โดยภาษา Python จะสามารถ Run ได้ 2 แบบ 1. Interpreter : การรันแบบ interpret คือการ run ที่ละบรรทัด เหมาะใช้ในงาน Data science 2. Compliler : การรันแบบ compile คือการที่เราเขียนเป็นไฟล์แล้ว run ทั้งหมดทีเดียว 



  •   PYTHON  BASIC

    •   syntax  :  indent สำคัญมาก เพราะ ไม่ใช้ {} และ ; ในการแบ่งบล็อคโค้ดเหมือนภาษาอื่น
         หลังเงื่อนไข (condition) มี : (colon)เสมอ เช่น เงื่อนไข if-else , เงื่อนไข loop
         เป็น Dynamic Programming ไม่ต้องระบุ Data type เหมือนภาษา java

    •   input  :  x = input('Enter your name:')

    •   output  :  print("Hello World !")

    •   Math  :  x = min(5, 10, 25)    x = max(5, 10, 25)    x = pow(4, 3)    x = math.sqrt(64)    x = math.pi
                     y = math.floor(1.4)   x = math.ceil(1.4)

    •   condition  :  if b > a:    elif a == b:    else:    TERNARY OPERATOR : print("A") if a > b else print("B")

    •   loop  :  while    ARRAY-LOOP : for x in array:    break    continue

    •   ในภาษา python มีชนิดข้อมูล (Data type) อะไรบ้าง ?  :  String    Tuple    List    Set    Dictionary    Boolean    Integer   Double

    •   Array  :  python ไม่มี Array แต่สามารถใช้ List เป็น Array ได้    CREATE : cars = ["Ford", "Volvo", "BMW"]    ACCESS : x = cars[0]    ARRAY-LENGHT : x = len(cars)    EDIT : cars[0] = "Toyota"    INSERT : cars.append("Honda")
         DELETE : cars.remove("Volvo")

    •   Tuple  :  CREATE : mytuple = ("apple", "banana", "cherry")    CHECK TYPE : print(type(thistuple))
         ACCESS : print(thistuple[1]) OR print(thistuple[2:5])    EDIT : y[1] = "kiwi"    ADD : y.append("orange")
         DELETE : y.remove("apple")    ARRAY-LOOP : for i in range(len(thistuple)):

    •   List  :  CREATE : mylist = ["apple", "banana", "cherry"]    ACCESS : print(thislist[1]) OR print(thislist[2:5])
         CHECK-IF-EXIST-IN-LIST : if "apple" in thislist: print("Yes")    EDIT : thislist[1] = "blackcurrant"
         2LIST-CONCAT : thislist.extend(thistuple)    ADD : thislist.insert(2, "watermelon") OR thislist.append("orange")

    •   String  :  print(len(str))    print("free" in txt)    print("expensive" not in txt)    SLICING : print(b[2:5])
         ลบ whitespacce หัวท้าย : print(a.strip())    print(str.replace("H", "J"))    แยกคำด้วย , : print(str.split(","))

    •   lampda  :  คือฟังก์ชั่นที่ไม่ต้องประกาศชื่อ เป็นการเขียนฟังก์ชั่นแบบ shorthand คล้ายๆ arrow function ในภาษา js แต่มีได้แค่ expression เดียว
         รับ a,b เข้ามาหาผลคูณเก็บใน x : x = lambda a, b : a * b

    •   File  :  f = open("demofile.txt")    print(f.read())    print(f.readline())    f.write("Now the file has more content!")    CHECK-IF-FILE-EXIST : if os.path.exists("demofile.txt"):


  •   PYTHON  OOP
    •   Function  :  CREATE : def my_function():    เรียกใช้ FUNCTION : my_function()

    •   Class  :  CREATE : class Person:    CONSTRUCTOR : def __init__(self, name): self.name = name
         เรียกใช้ CLASS : p1 = Person("John")    ใช้ PARAMETER ที่ CLASS รับมา : print(p1.name)
         ใช้ PARAMETER ที่ CLASS รับมาใน FUNCTION ต้องมี self.: def welcome(self):print("Welcome", self.firstname)

    •   Inheritance  :  CREATE : class Student(Person):    เรียกใช้ CLASS : p1 = Person("John")
         CONSTRUCTOR ต้องระบุ PARAMETER ทุกตัวที่ superclass รับมาคลาสลูกก็ต้องมี : def __init__(self, fname, lname):super().__init__(fname, lname)

    •   Polymorphism  : 

    •   OOP Design  :  คือ การออกแบบโปรแกรมแบบ OOP ทำยังไง


  •   PYTHON  DATABASE

    •   MySQL

       1. โหลด API/MySQL Driver ทีชื่อ MySQL Connector แนะนำให้โหลดผ่าน PIP - PIP คือ Package management ของ python คือ โมดูลที่รวม library/package ต่างๆไว้ให้เรา install ได้จากที่เดียว โดยใช้คำสั่ง cmd สะดวกมาก pip จะถูก install มาพร้อมกับตอนที่เราลง python วิธีเช็คว่า คอมเรามี pip ยังอาจะทำได้โดยการเช็ค version ผ่านคำสั่ง cmd : pip --version ถ้าเช็คแล้วว่ามี pip แล้ว ให้ใช้ pip ช่วย install " MySQL Connector " package ด้วยคำสั่ง 

      python -m pip install mysal-connector-python

       2. เริ่มใช้ได้เลย Algorithm ในการ connnect database จะมีขั้นตอนดังนี้ 2.1 import คลาส mysql.connector ที่เรา install เมื่อกี้มา เพื่อที่จะสามารถใช้ คำสั่งต่างๆ(method) ภายในคลาสได้ 2.2 create connection โดยใช้ method ที่ชื่อ connect เป็น method ที่รับ parameter ดังนี้ host,user,password, database ดังนั้นเวลาจะใช้ใช้ต้องระบุ parameter พวกนี้ 2.3 ตอนนี้เรา connect database สำเร็จแล้ว ก็สามารถ create read update delete ข้อมูลใน database นั้นด้วยคำสั่ง SQL ได้แล้ว โดยต้องใช้ method cursor กับ method execute ในการเขียนคำสั่ง SQL 

      ตัวอย่าง : เขียน python เชื่อมต่อฐานข้อมูล MySQL เพื่อ Create Table ชื่อ customers มี column ชื่อ id เป็น primary key

       import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase" ) mycursor = mydb.cursor() mycursor.execute("CREATE TABLE customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))") 


    •   MongoDB  : 



  •   PYTHON  GUI
    •   TKinter  : 
    •   PyQT  : 

  •   PYTHON  WEB
    •   Django คืออะไร ?  : 
    •   Flask คืออะไร ?  : 
    •   web scrapping คืออะไร ?  : 
    •   API คืออะไร ?  : 

  •   PYTHON  DATA  SCIENCE
    •   Data Sciencetist ต่างจาก AI Engineer ยังไง ?  : 
    •   Data Engineer  :  pandas , spark , ci-cd
    •   Data Analyst  :  mathplotlib , Numpy



3. )    Python  Exercise

  •   Beginner  Level  ( เป็นโจทย์เหมาะสำหรับฝึกใช้คำสั่งพื้นฐานให้คล่อง ให้คุ้นเคยกับ syntax )  : 

  •   Intermediate  Level  ( เป็นโจทย์ที่ทำให้เราได้ฝึกเอาพื้นฐานมาประยุกต์ใช้สร้าง Product จริงๆ )  : 

    • practicepython :  โจทย์ส่วนมากเป็นเกม เช่น tic tac toe มีอธิบายโค้ด เหมาะใช้ฝึกอ่านทำความเข้าใจวิธีเขียนโค้ดของคนอื่น เพื่อมาประยุกต์ใช้
    • hackerrank  :  เลือกระดับได้ คล้ายๆ leetcode เหมาะใช้ฝึก interview coding เตรียมตัวก่อนไปสัมภาษณ์งาน
    • edabit  :  เลือกระดับได้ คล้ายๆ leetcode เหมาะใช้ฝึก interview coding เตรียมตัวก่อนไปสัมภาษณ์งาน
  •   Advanced  Level  ( เป็นการทำ Project อาจจะ opensource )  : 

    • jetbrains  :  พาทำโปรเจคน่าสนใจ เช่น Password Hacker (Python) แต่ไม่ฟรี

About

: Python Programming

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages