FlashKeepers

Python · Python · College and University

Python 基礎:語法與資料型別

Python 的核心語法、變數型別與常見資料結構(串列、字典、元組),每個主題都附有簡短範例說明。

About this set

43 basic cards for Python Python. It opens with "Python 中的變數是什麼?" and "在 Python 中如何將值指定給變數?". More College and University decks are listed below.

43 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

Python 中的變數是什麼?
Show answer用名稱來儲存一個值的容器。只要指定一次,之後就能在程式中用這個名稱來取用。
在 Python 中如何將值指定給變數?
Show answer使用等號(=)。範例:name = 'Alice'
Python 的動態型別是什麼意思?
Show answer變數的型別由執行時指定給它的值決定,重新指定後型別也可能改變。
Python 的 int 資料型別是什麼?
Show answer用來表示沒有小數點的整數的資料型別。範例:x = 5
Python 的 float 資料型別是什麼?
Show answer用來表示帶有小數點的數字的資料型別。範例:pi = 3.14
Python 的 str 資料型別是什麼?
Show answer用引號(單引號、雙引號或三引號)包起來的一串字元。範例:text = 'Hello'
Python 的 bool 資料型別是什麼?
Show answer只有兩個值的資料型別:True 或 False。
在 Python 中如何建立串列(list)?
Show answer使用方括號,並以逗號分隔各個值。範例:nums = [1, 2, 3]
如何取得串列中的單一元素?
Show answer在方括號中放入索引。範例:nums[0] 會回傳第一個元素。
Python 的串列索引是什麼?
Show answer元素在串列中的位置,第一個元素的位置是 0。
Python 的負索引是什麼?
Show answer使用負數從串列的尾端往前取元素。範例:nums[-1] 是最後一個元素。
如何在串列中新增元素?
Show answer使用 append() 方法。範例:nums.append(4) 會把 4 加到串列的最後面。
如何從串列中移除元素?
Show answer用 remove() 依值刪除,或用 pop() 依索引刪除。範例:nums.remove(2) 或 nums.pop(0)
Python 的元組(tuple)是什麼?
Show answer用小括號包起來的有序元素集合,建立之後就不能更改。
如何建立元組?
Show answer使用小括號,並以逗號分隔各個值。範例:coords = (10, 20)

28 more cards in the app

Study this set free