Skip to content

Chapter 2 Getting Started

CHAPTER 2

Getting Started

Keynote

1.1 Python Specification

  • Python cu language (computer holh) caah specification (tial ning phunglam) a si i, lam phunphun in implemented (tuah/hman) khawh a si. Holh phunphun in tial mi hi specification i implementations tampi a um.

  • A lar mi Python implementations pawl cu:

  • CPython - hi zohchunh awk implementation a si, C in tial a si.
  • PyPy - Python language i a hmete a simi RPython in tial a si.
  • Jython - Java in tial a si.
  • IronPython - C# in tial a si.

  • Hi implementations dihlak hi compilers an si i interpreters zong an si fawn. Compiler nih Python program kha a lailing a simi bytecode ah a thlen (converts). Mah bytecode cu interpreter nih a leh (interpreted) á¹­han.


1.2 Windows Cung Ah Python Installation Tuah Ning

  • Python cu kum tampi chung a á¹­hangcho ve. Hi edition (cauk) á¹­ial lio i a thar bik version, Windows le Linux caah Python 3.14.1 a si.

  • Python cu Windows OS ah aa tel chih lo. Cucaah a dang tein install tuah a hau. Mah caah cun www.python.org/downloads/ in Python installer kha download tuah a hau.

  • Download na tuah tik ah, na hmanmi computer cu 32-bit machine a si maw 64-bit machine a si maw timi cung ah hngat in installer aa tlak mi thim ding a si:

  • 64-bit machine: Windows x86-64 executable installer kha download tuah.
  • 32-bit machine: Windows x86 executable installer kha download tuah.

  • Installer na thim i download na tuah dih in, file kha hmeh-hnih (double-clicking) in tuahter/on. Figure 2.1 ah langhter mi dialog (cakuang) kha screen cung ah a lang lai. Fig 2.1 Python 3.14.1 Installer Screen

  • Mah dialog chung ah, interpreter kha na execution path chung ah a um nakhnga, 'Add Python 3.14 to PATH' asiloah 'Add python.exe to PATH' timi check box (kakuang te) kha hmanh-thut (check) tuah ding a biapi tuk.

  • 'Install Now' kha hmet law minit tlawmpal chung ah installation cu a tlamtling lai. Python files pawl cu a tanglei directory (hmun) ah install tuah an si lai: C:\Users\Joseph\AppData\Local\Programs\Python\Python314

  • Hi path chung i ‘Joseph’ timi cu user name (hman tu min) a si i ‘Python314’ timi cu na download i install tuah mi Python installation i a version number a si.

  • Check box kha hmanh-thut na philh sual a si ahcun, a cunglei i langhter mi path kha Control Panel | System | Environment Variables | Edit hmang in PATH variable ah na chap khawh. PATH variable chung ah values tampi semicolon (;) in á¹­hen in an um cia. A cunglei path kha a um cia mi values hnu ah va chap.

  • Installation a dih tik ah, command prompt on in python --version tiah type tuah law na chek khawh.

  • Installation a tlam a tlin ahcun, na system chung i install tuah mi Python i a version na hmuh lai.

  • Windows 10 na hman a si ahcun, Settings > Apps > Apps & features > Python ah kal in installation kha na chek khawh.

  • Windows 11 na hman a si ahcun, Settings >Apps > Apps & features > Python ah kal in installation kha na chek khawh.


1.3 Linux Cung Ah Python Installation Tuah Ning

  • Linux distributions a tam deuh (tahchunhnak ah Ubuntu) ah cun Python a um cia. Asinain, a um cia mi Python version cu a thar bik a si lo kho men. A tanglei bantuk in version na chek khawh:

    Check Python Version
    python3 --version
    
  • Version cu a thar bik a si lo tiah na hmuh ahcun, command hmang in a thar bik version (tahchunhnak ah Python 3.13) kha install na tuah khawh:

    Install Python
    sudo apt update
    sudo apt install python3.13
    

1.4 Python Resources (Bawmtu Thilri Pawl)


1.5 Third-party Packages (Midang Tuah Mi Packages)

  • Python community chung i Pythonistas pawl nih packages (libraries) an ser i programmers dang hman khawh dingin an chiah. An packages á¹­henhnak caah PyPI—Python Package Index (www.pypi.org) an hmang.

  • PyPI nih third-party Python packages hmuh khawh mi cazin a ngei/kilkawicawi.

  • Thil tuahnak ding caah a herh mi third-party packages a phunphun a um. Data Science applications sernak caah hman tawn mi packages cheukhat cu:

  • NumPy: Mathematical operations a sang mi tuahnak caah le multi-dimensional arrays le matrices ngan pipi support tuahnak caah a si.
  • SciPy: Scientific computing library a si i optimization, integration, interpolation, signal processing, image processing, tbk. caah hman a si.
  • Pandas: Numerical tables le time series tawlrelnak caah Library a si.
  • MatPlotLib: 2D le 3D Data visualization library (Data hmanthlak in langhternak) a si.
  • OpenCV: Open source Computer vision library a si.

1.6 Python Packages Le Development Tools

  • Nangmah zong PyPI ah register na tuah kho i na packages pawl na upload khawh ve. Package ser ning, build tuah ning le Python Package Index ah upload tuah ning kong he pehtlai in www.pypi.org ah lam hmuhsaknak an pek mi na zulh a hau.

  • pip cu PyPI in packages install tuahnak caah hman tawn mi tool a si. Python na install tik ah hi tool hi amah tein a ra chih.

1.6.1 Data Science Le AI Tools

  • Python programmers pawl Data Science le Artificial Intelligence applications sernak le document tuahnak ah bawmtu ding tools tampi a um. Cu hna cu:
  • Jupyter Notebook - Hi tool cu browser cung ah hman khawh mi a si i Python (le languages dang) he hman á¹­i khawh a si. Python code, code nih a chuah mi output le visualization asiloah plot tbk. pawl kha Notebook tiah auh mi document pakhat chung ah chiah á¹­i a ngah. Modular program development tuahnak caah tool á¹­ha taktak a si.
  • Google Colab - Hi tool nih Google's cloud servers cung ah code execute (tuahter) nak ding caah Jupyter notebook environment kha a man pek hau lo in a pek. Cucaah, Google's hardware á¹­hawnnak kha na hmang kho.
  • Spyder - Hi tool nih Scientific Python Development Environment kha testing le debugging features a á¹­ha mi he a pek.

  • Jupyter le Spyder cu Anaconda tiah auh mi software distribution a lar taktak mi chung i a tel mi an si. Cucaah Anaconda na download i install na tuah ahcun, Jupyter le Spyder kha a ready in na hmuh colh lai.

1.6.2 IDLE (Integrated Development and Learning Environment)

  • Python install na tuah dih in, amah he a ra chih mi Python Integrated Development and Learning Environment (IDLE) hmang in program development tuah khawh a si.

  • IDLE cu development tool á¹­ha a si. Amah nih syntax highlighting, context-sensitive help le debugging tbk. features á¹­ha a ngei.

  • Syntax highlighting feature nih keywords, functions, methods le strings pawl kha a color (muizawng) a dang cio in a langhter hna caah hngalh an fawi.
  • Context-sensitive help cu program na á¹­ial lio ah bawmhnak na herhnak zawn paoh ah Ctrl + Space hmeh in hmuh khawh a si. Functions, methods le an parameters min dihlak cinken dih ding a har tuk caah hi feature hi a á¹­hahnem tuk.
  • Debugger nih program a kal ning (flow of execution) a zulh (trace) i na program chung i logical errors (palhnak) um mi kawl khawhnak a pek. Hi tracing cu break points chiah in le single stepping (kar khat hnu kar khat) in tuah khawh a si. Cuti na tuah lio ah IDLE nih execution a kal lio i variables values aa thlen ning pawl a langhter.

1.6.3 Python Modes

  • Python cu modes (lam) pahnih in hman khawh a si:
  • Interactive mode - Python syntax hlathlai nak, bawmhnak hal nak le programs tawi te debug tuahnak caah hman a si.
  • Script mode - Python programs a tling mi á¹­ialnak caah hman a si.

  • Hi modes pahnih hi IDLE nih a support.

1.6.3.1 IDLE Kha Interactive Mode In Hman Ning:
  • Windows ah IDLE tiah Windows search bar ah á¹­ial in kawl law enter hmet, asiloah IDLE icon kha double click tuah.
  • >>> Python shell prompt a um mi Python shell window a hong lai.
  • A tanglei Python code hi prompt ah khan execute (tuahter) tuah.

    >>> print('Keep calm and bubble on')
    
  • 'Keep calm and bubble on' timi message kha >>> prompt hnu ah a langhter lai.

1.6.3.2 IDLE Kha Script Mode In Hman Ning:
  • IDLE kha on (Launch). IDLE shell window chung i menu in File | New File kha thim. Window thar a hong lai. A tanglei script hi á¹­ial:

    print('Those who can\'t laugh at themselves…')
    print('leave the job to others.')
    
  • File | Save kha hmang law script kha 'Test.py' tiah min pek in save tuah.

  • Run menu hmang in asiloah F5 hmeh in script kha execute tuah. Message pahnih kha a print lai.
1.6.3.3 Other IDEs Hmannak
  • IDLE hman lo in NetBeans asiloah Visual Studio Code hman na duh ahcun a tanglei steps hi zul:
  • Python project thar ‘Test’ tiah min pek in ser law.
  • Script kha Test.py chung ah á¹­ial.
  • NetBeans ah F6 asiloah Visual Studio Code ah Ctrl + F5 hmang in script kha execute tuah.
  • Execution a tuah tik ah catlang pahnih kha a print lai, cun project thar le script thar ser ding in a ready lai.

1.7 Python Version Cheknak

  • Python cu kum tampi chung a á¹­hangcho. Na machine cung i install tuah mi version kha Python script tawi te hmang in na hngalh khawh:
Check Python Version
import sys
print(sys.version)

Exerciese

[A] A tanglei biahalnak hna hi phi tuah:

  • a. C:\>, $, le >>> prompts pawl nih zeidah an langhter (signify)?
  • b. IDLE cu zei modes (lam) pahnih in dah hman khawh a si?
  • c. IDLE nih a pek mi programming modes pahnih hna i an hman-hnawhchan (purpose) cu zei dah a si?
  • d. Third-party libraries pawl cu Python Program nih zeitin dah hman khawh an si?

[B] A tanglei pawl hi a kop in thleidan tuah (Match the following pairs):

Section A Section B
a. pip 1. Mathematical operations le matrices caah.
b.CPython 2. Scientific Python Development Environment** a si caah Scientific Computing he aa tlak bik.
c. Spyder 3.Numerical tables le time series tawlrelnak.
d.PyPI 4. 2D le 3D Data visualization (Data hmanthlak in langhter).
e.NumPy 5. Computer vision library.
f.SciPy 6. PyPI in packages install tuahnak hriamnam.
g.Pandas 7. Code le visualization tial á¹­i nak document sernak.
h.MatPlotlib 8. Scientific computing library a si.
i.OpenCV 9.Third-party packages á¹­henhnak hmun.

Answers

Section A Section B (A Phi) A Sullam (Reference)
a. pip 6. Package installation tool PyPI in packages install tuahnak hriamnam.
b. Jupyter 7. Build and document applications Code le visualization tial á¹­i nak document sernak.
c. Spyder 2. Scientific Computing Scientific Python Development Environment a si caah Scientific Computing he aa tlak bik.
d. PyPI 9. Python Package index Third-party packages á¹­henhnak hmun.
e. NumPy 1. Advanced mathematical operations Mathematical operations le matrices caah.
f. SciPy 8. Scientific Library Scientific computing library a si.
g. Pandas 3. Manipulation numerical tables Numerical tables le time series tawlrelnak.
h. MatPlotlib 4. Visualization 2D le 3D Data visualization (Data hmanthlak in langhter).
i. OpenCV 5. Computer Vision Computer vision library.

[C] A tanglei bia hna hi a Hmaan (True) le a Hmaan lo (False) chim tuah:

  • a. Python cu specification a si i Python (PyPy), C# (IronPython), Java (Jython), tbk. hmang in implementation tuah khawh a si.
  • A Phi: True (Hmaan).

  • b. CPython cu Python specification i implementation a si i, C in á¹­ial a si.

  • A Phi: True (Hmaan).

  • c. Python program cu byte code ah compile tuah hmasa a si i, cu hnu ah interpreted (leh) a si.

  • A Phi: True (Hmaan).

  • d. Linux distributions a tam deuh nih Python an ngei cia.

  • A Phi: True (Hmaan).

  • e. Windows system nih Python a ngei lo i a dang tein install tuah a hau.

  • A Phi: True (Hmaan).

  • f. Python programs pawl cu IDLE, Netbeans, PyCharm le Visual Studio Code hmang in ser khawh a si.

  • A Phi: True (Hmaan).

  • g. Third-party Python packages pawl cu PyPI hmang in á¹­henh (distributed) an si.

  • A Phi: True (Hmaan).


Comments