週次 | 課程內容 | 重要事件 |
---|---|---|
第1週 | 程式設計概論 | |
第2週 | 基本語法介紹 | |
第3週 | 控制結構 | |
第4週 | 函數與模組 | |
第5週 | 資料結構簡介 | |
第6週 | 實作練習 | |
第7週 | 第一次報告 | 報告主題:前六週內容 |
第8週 | 物件導向程式設計 | |
第9週 | 例外處理與調試 | |
第10週 | 資料庫基礎 | |
第11週 | 網頁程式設計基礎 | |
第12週 | 實作練習 | |
第13週 | 專題討論 | |
第14週 | 第二次報告 | 報告主題:第8-13週內容 |
第15週 | 資料分析簡介 | |
第16週 | 前端與後端技術 | |
第17週 | 專題實作 | |
第18週 | 課程回顧 | |
第19週 | 期末考試準備 | |
第20週 | 期末考試 | |
第21週 | 期末報告 | 報告主題:整體課程總結 |
程式語言 | 變數定義方式示例 | 說明 |
---|---|---|
Python | x = 10 | 直接使用 = 進行賦值,支持多種類型。 |
Java | int x = 10; | 需要指定變數類型,結尾有分號。 |
JavaScript | let x = 10; | 使用 let、const 或 var 來定義變數。 |
C++ | int x = 10; | 需要指定變數類型,結尾有分號。 |
C# | int x = 10; | 類似於 Java 和 C++,需要指定類型。 |
Ruby | x = 10 | 類似於 Python,無需指定類型。 |
PHP | $x = 10; | 變數以 $ 開頭,無需指定類型。 |
Swift | var x = 10 | 使用 var 定義可變變數,無需指定類型。 |
變數類型示例
name = "Alice" # 字串
age = 30 # 整數
height = 5.7 # 浮點數
String name = "Alice"; // 字串
int age = 30; // 整數
double height = 5.7; // 浮點數
let name = "Alice"; // 字串
let age = 30; // 整數
let height = 5.7; // 浮點數
#include <iostream>
using namespace std;
int main() {
string name = "Alice"; // 字串
int age = 30; // 整數
double height = 5.7; // 浮點數
return 0;
}
string name = "Alice"; // 字串
int age = 30; // 整數
double height = 5.7; // 浮點數
name = "Alice" # 字串
age = 30 # 整數
height = 5.7 # 浮點數
$name = "Alice"; // 字串
$age = 30; // 整數
$height = 5.7; // 浮點數
var name = "Alice" // 字串
var age = 30 // 整數
var height = 5.7 // 浮點數
宣告變數的方式
Python範例:
x = 10 # 整數
name = "John" # 字串
變數命名規則:只能包含字母、數字和下劃線,不能以數字開頭。
不同程式語言在運算式表示方面存在一些差異,主要體現在運算符的符號、優先級和結合性等方面。以下是一些常見程式語言中運算式的表示方式示例:
運算符 | 描述 | Python | Java | JavaScript | C++ | C# | Ruby | PHP | Swift |
---|---|---|---|---|---|---|---|---|---|
+ | 加法 | + | + | + | + | + | + | + | + |
- | 減法 | - | - | - | - | - | - | - | - |
* | 乘法 | * | * | * | * | * | * | * | * |
/ | 除法 | / | / | / | / | / | / | / | / |
% | 取餘數(模運算) | % | % | % | % | % | % | % | % |
** | 指數運算 | ** | ** | ** | ** | ** | ** | ** | ** |
運算符 | 描述 | Python | Java | JavaScript | C++ | C# | Ruby | PHP | Swift |
---|---|---|---|---|---|---|---|---|---|
== | 等於 | == | == | == | == | == | == | == | == |
!= | 不等於 | != | != | != | != | != | != | != | != |
> | 大於 | > | > | > | > | > | > | > | > |
< | 小於 | < | < | < | < | < | < | < | < |
>= | 大於等於 | >= | >= | >= | >= | >= | >= | >= | >= |
<= | 小於等於 | <= | <= | <= | <= | <= | <= | <= | <= |
and | 邏輯與 | and | && | && | && | && | && | && | && |
or | 邏輯或 | or | |||||||
not | 邏輯非 | not | ! | ! | ! | ! | ! | ! | ! |
運算符 | 描述 | Python | Java | JavaScript | C++ | C# | Ruby | PHP | Swift |
---|---|---|---|---|---|---|---|---|---|
= | 賦值 | = | = | = | = | = | = | = | = |
+= | 加法賦值 | += | += | += | += | += | += | += | += |
-= | 減法賦值 | -= | -= | -= | -= | -= | -= | -= | -= |
*= | 乘法賦值 | *= | *= | *= | *= | *= | *= | *= | *= |
/= | 除法賦值 | /= | /= | /= | /= | /= | /= | /= | /= |
%= | 取餘數賦值 | %= | %= | %= | %= | %= | %= | %= | %= |
**= | 指數賦值 | **= | **= | **= | **= | **= | **= | **= | **= |
運算符 | 描述 | Python | Java | JavaScript | C++ | C# | Ruby | PHP | Swift |
---|---|---|---|---|---|---|---|---|---|
**. ** | 成員訪問 | . | . | . | . | . | . | -> | . |
**[] ** | 索引訪問 | [] | [] | [] | [] | [] | [] | [] | [] |
**() ** | 函數調用 | () | () | () | () | () | () | () | () |
不同語言的運算符優先級和結合性可能略有不同,建議查閱相關語言的文檔以獲取詳細信息。
示例
# python
result = (10 + 5) * 2 # 計算結果為 30
# java
int result = (10 + 5) * 2; // 計算結果為 30
# JavaScript
let result = (10 + 5) * 2; // 計算結果為 30
# C++
int result = (10 + 5) * 2; // 計算結果為 30
# C#
int result = (10 + 5) * 2; // 計算結果為 30
# Ruby
result = (10 + 5) * 2 # 計算結果為 30
# PHP
$result = (10 + 5) * 2; // 計算結果為 30
# Swift
let result = (10 + 5) * 2 // 計算結果為 30
不同程式語言的運算式表示方式各有特點,了解這些差異可以幫助你更有效地理解和編寫程式碼。建議在學習程式設計時,仔細閱讀相關語言的文檔,以掌握其運算符的用法和優先級。
在不同的程式語言中,控制結構 if、else 和 elif 的表示方式可能略有不同,但其基本邏輯和功能是相同的。以下是一些常見程式語言中控制結構的表示方式示例:
程式語言 | if 語句示例 | 說明 |
---|---|---|
Python | if condition: | 使用 : 結尾,縮進表示程式區塊。 |
Java | if (condition) { … } | 使用 {} 包裹程式區塊。 |
JavaScript | if (condition) { … } | 使用 {} 包裹程式區塊。 |
C++ | if (condition) { … } | 使用 {} 包裹程式區塊。 |
C# | if (condition) { … } | 使用 {} 包裹程式區塊。 |
Ruby | if condition then … end | 使用 then 和 end 標記程式區塊。 |
PHP | if (condition) { … } | 使用 {} 包裹程式區塊。 |
Swift | if condition { … } | 使用 {} 包裹程式區塊。 |
程式語言 | else 語句示例 | 說明 |
---|---|---|
Python | else: | 使用 : 結尾,縮進表示程式區塊。 |
Java | else { … } | 使用 {} 包裹程式區塊。 |
JavaScript | else { … } | 使用 {} 包裹程式區塊。 |
C++ | else { … } | 使用 {} 包裹程式區塊。 |
C# | else { … } | 使用 {} 包裹程式區塊。 |
Ruby | else … end | 使用 else 和 end 標記程式區塊。 |
PHP | else { … } | 使用 {} 包裹程式區塊。 |
Swift | else { … } | 使用 {} 包裹程式區塊。 |
程式語言 | elif 語句示例 | 說明 |
---|---|---|
Python | elif condition: | 使用 : 結尾,縮進表示程式區塊。 |
Java | else if (condition) { … } | 使用 else if 進行多重條件判斷。 |
JavaScript | else if (condition) { … } | 使用 else if 進行多重條件判斷。 |
C++ | else if (condition) { … } | 使用 else if 進行多重條件判斷。 |
C# | else if (condition) { … } | 使用 else if 進行多重條件判斷。 |
Ruby | elsif condition then … end | 使用 elsif 和 end 標記程式區塊。 |
PHP | elseif (condition) { … } | 使用 elseif 進行多重條件判斷。 |
Swift | else if condition { … } | 使用 else if 進行多重條件判斷。 |
radius = float(input("請輸入圓形的半徑: "))
area = 3.14159 * radius * radius
print("圓形的面積是:", area)
score1 = int(input("請輸入第一個分數: "))
score2 = int(input("請輸入第二個分數: "))
score3 = int(input("請輸入第三個分數: "))
average_score = (score1 + score2 + score3) / 3
print("平均分數是:", average_score)
original_price = float(input("請輸入商品原價: "))
discount_rate = float(input("請輸入折扣率 (例如 0.2 代表 20%): "))
discount_price = original_price * (1 - discount_rate)
print("折扣價是:", discount_price)
age = 25
if age < 18:
print("未成年")
elif age >= 18 and age < 65:
print("成年")
else:
print("老年")
int age = 25;
if (age < 18) {
System.out.println("未成年");
} else if (age >= 18 && age < 65) {
System.out.println("成年");
} else {
System.out.println("老年");
}
let age = 25;
if (age < 18) {
console.log("未成年");
} else if (age >= 18 && age < 65) {
console.log("成年");
} else {
console.log("老年");
}
#include <iostream>
using namespace std;
int main() {
int age = 25;
if (age < 18) {
cout << "未成年" << endl;
} else if (age >= 18 && age < 65) {
cout << "成年" << endl;
} else {
cout << "老年" << endl;
}
return 0;
}
using System;
class Program {
static void Main(string[] args) {
int age = 25;
if (age < 18) {
Console.WriteLine("未成年");
} else if (age >= 18 && age < 65) {
Console.WriteLine("成年");
} else {
Console.WriteLine("老年");
}
}
}
age = 25
if age < 18
puts "未成年"
elsif age >= 18 and age < 65
puts "成年"
else
puts "老年"
end
<?php
$age = 25;
if ($age < 18) {
echo "未成年";
} elseif ($age >= 18 && $age < 65) {
echo "成年";
} else {
echo "老年";
}
?>
let age = 25
if age < 18 {
print("未成年")
} else if age >= 18 && age < 65 {
print("成年")
} else {
print("老年")
}
不同程式語言的控制結構語法略有差異,但其邏輯和功能是一致的。了解這些差異可以幫助你更有效地理解和編寫程式碼。在學習程式設計時,建議仔細閱讀相關語言的文檔,以掌握其控制結構的用法和語法規則。
第二次段考作業
https://blockly.games/?lang=zh-hant
電競訓練營:人工智能聯盟
https://hourofcode.com/codecombatesports
以下是不同語法對控制結構 For 和 While 的表示方式:
C 語言
for (initialization; condition; increment) {
// code to be executed
}
# 初始化;狀態;增量
while (condition) {
// code to be executed
}
Python 語言
for item in iterable:
# code to be executed
while condition:
# code to be executed
JavaScript 語言
for (initialization; condition; increment) {
// code to be executed
}
while (condition) {
// code to be executed
}
Java 語言
for (initialization; condition; increment) {
// code to be executed
}
while (condition) {
// code to be executed
}
PHP 語言
for (initialization; condition; increment) {
// code to be executed
}
while (condition) {
// code to be executed
}
Go 語言
for initialization; condition; increment {
// code to be executed
}
for condition {
// code to be executed
}
Swift 語言
for item in iterable {
// code to be executed
}
while condition {
// code to be executed
}
Kotlin 語言
for (item in iterable) {
// code to be executed
}
while (condition) {
// code to be executed
}
Ruby 語言
for item in iterable do
# code to be executed
end
while condition do
# code to be executed
end
C# 語言
for (initialization; condition; increment) {
// code to be executed
}
while (condition) {
// code to be executed
}
小結
不同的程式語言對於 For 和 While 迴圈的語法細節可能略有不同,但它們的基本概念是相同的:
以下是一些 For 和 While 迴圈的範例,以說明它們在不同程式語言中的用法:
1. C 語言
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
printf("%d\n", i);
}
return 0;
}
#include <stdio.h>
int main() {
int i = 1;
int sum = 0;
while (i <= 10) {
sum += i;
i++;
}
printf("總和為:%d\n", sum);
return 0;
}
2. Python 語言
my_list = ["蘋果", "香蕉", "橘子"]
for fruit in my_list:
print(fruit)
number = 1
while number != 0:
number = int(input("請輸入一個數字 (輸入 0 結束): "))
print("您輸入的數字是:", number)
3. JavaScript 語言
for (let i = 1; i <= 5; i++) {
console.log(i * i);
}
let input = "";
while (input !== "結束") {
input = prompt("請輸入一個字串 (輸入 \"結束\" 結束): ");
console.log("您輸入的字串是:", input);
}
4. Java 語言
public class Main {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum += i;
}
System.out.println("總和為:" + sum);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number = 1;
while (number >= 0) {
System.out.print("請輸入一個數字 (輸入負數結束): ");
number = scanner.nextInt();
System.out.println("您輸入的數字是:" + number);
}
}
}
5. PHP 語言
$fruits = array("蘋果", "香蕉", "橘子");
for ($i = 0; $i < count($fruits); $i++) {
echo $fruits[$i] . "<br>";
}
$input = "";
while ($input !== "結束") {
$input = readline("請輸入一個文字 (輸入 \"結束\" 結束): ");
echo "您輸入的文字是:" . $input . "<br>";
}
6. Go 語言
package main
import "fmt"
func main() {
for i := 1; i <= 5; i++ {
if i%2 == 0 {
fmt.Println(i)
}
}
}
package main
import "fmt"
func main() {
number := 1
for number != 0 {
fmt.Print("請輸入一個數字 (輸入 0 結束): ")
fmt.Scanln(&number)
fmt.Println("您輸入的數字是:", number)
}
}
7. Swift 語言
for i in 1...10 {
print(i)
}
var input = ""
while input != "結束" {
input = readLine()!
print("您輸入的文字是:", input)
}
8. Kotlin 語言
for (i in 1..5) {
println(i * i)
}
import java.util.*
fun main() {
val scanner = Scanner(System.`in`)
var number = 1
while (number >= 0) {
print("請輸入一個數字 (輸入負數結束): ")
number = scanner.nextInt()
println("您輸入的數字是:" + number)
}
}
9. Ruby 語言
fruits = ["蘋果", "香蕉", "橘子"]
fruits.each do |fruit|
puts fruit
end
input = ""
while input != "結束"
input = gets.chomp
puts "您輸入的文字是:" + input
end
10. C# 語言
using System;
public class Program {
public static void Main(string[] args) {
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum += i;
}
Console.WriteLine("總和為:" + sum);
}
}
using System;
public class Program {
public static void Main(string[] args) {
int number = 1;
while (number >= 0) {
Console.Write("請輸入一個數字 (輸入負數結束): ");
number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("您輸入的數字是:" + number);
}
}
}
以下是一些常見程式語言中函數和模組的表示方式:
1. C 語言
#include <stdio.h>
// 函數定義
int sum(int a, int b) {
return a + b;
}
int main() {
int result = sum(3, 5);
printf("3 + 5 = %d\n", result);
return 0;
}
C 語言本身沒有明確的模組概念,但可以使用頭文件(.h)和源文件(.c)來模擬模組化。
2. Python 語言
def sum(a, b):
return a + b
result = sum(3, 5)
print("3 + 5 =", result)
Python 使用檔案來表示模組。例如,一個名為 my_module.py
的檔案可以包含以下程式碼:
def sum(a, b):
return a + b
def greet(name):
print("Hello,", name)
然後,在另一個檔案中,可以使用 import
語句導入模組:
import my_module
result = my_module.sum(3, 5)
print("3 + 5 =", result)
my_module.greet("Alice")
3. JavaScript 語言
function sum(a, b) {
return a + b;
}
let result = sum(3, 5);
console.log("3 + 5 =", result);
JavaScript 使用 export
和 import
來定義和導入模組。例如,一個名為 my_module.js
的檔案可以包含以下程式碼:
export function sum(a, b) {
return a + b;
}
export function greet(name) {
console.log("Hello,", name);
}
然後,在另一個檔案中,可以使用 import
語句導入模組:
import { sum, greet } from './my_module.js';
let result = sum(3, 5);
console.log("3 + 5 =", result);
greet("Alice");
4. Java 語言
public class Main {
public static int sum(int a, int b) {
return a + b;
}
public static void main(String[] args) {
int result = sum(3, 5);
System.out.println("3 + 5 = " + result);
}
}
Java 使用類別來表示模組。例如,一個名為 MyModule.java
的檔案可以包含以下程式碼:
public class MyModule {
public static int sum(int a, int b) {
return a + b;
}
public static void greet(String name) {
System.out.println("Hello, " + name);
}
}
然後,在另一個檔案中,可以使用 import
語句導入模組:
import MyModule;
public class Main {
public static void main(String[] args) {
int result = MyModule.sum(3, 5);
System.out.println("3 + 5 = " + result);
MyModule.greet("Alice");
}
}
5. Go 語言
package main
import "fmt"
func sum(a, b int) int {
return a + b
}
func main() {
result := sum(3, 5)
# := 表示聲明一個新變數,並將 sum(3, 5) 的結果賦予它。
# := 運算子只能在 函數內部 使用,不能在函數外部使用。
fmt.Println("3 + 5 =", result)
}
Go 使用包(package)來表示模組。例如,一個名為 my_module
的包可以包含以下程式碼:
package my_module
func sum(a, b int) int {
return a + b
}
func greet(name string) {
fmt.Println("Hello,", name)
}
然後,在另一個檔案中,可以使用 import
語句導入模組:
package main
import "fmt"
import "my_module"
func main() {
result := my_module.sum(3, 5)
fmt.Println("3 + 5 =", result)
my_module.greet("Alice")
}
6. Swift 語言
func sum(a: Int, b: Int) -> Int {
return a + b
}
let result = sum(a: 3, b: 5)
print("3 + 5 =", result)
Swift 使用檔案來表示模組。例如,一個名為 MyModule.swift
的檔案可以包含以下程式碼:
func sum(a: Int, b: Int) -> Int {
return a + b
}
func greet(name: String) {
print("Hello,", name)
}
然後,在另一個檔案中,可以使用 import
語句導入模組:
import MyModule
let result = MyModule.sum(a: 3, b: 5)
print("3 + 5 =", result)
MyModule.greet(name: "Alice")
7. Kotlin 語言
fun sum(a: Int, b: Int): Int {
return a + b
}
fun main() {
val result = sum(3, 5)
println("3 + 5 = $result")
}
Kotlin 使用檔案來表示模組。例如,一個名為 MyModule.kt
的檔案可以包含以下程式碼:
package my_module
fun sum(a: Int, b: Int): Int {
return a + b
}
fun greet(name: String) {
println("Hello, $name")
}
然後,在另一個檔案中,可以使用 import
語句導入模組:
import my_module.*
fun main() {
val result = sum(3, 5)
println("3 + 5 = $result")
greet("Alice")
}
8. PHP 語言
function sum($a, $b) {
return $a + $b;
}
$result = sum(3, 5);
echo "3 + 5 = " . $result . "<br>";
PHP 使用檔案來表示模組。例如,一個名為 my_module.php
的檔案可以包含以下程式碼:
function sum($a, $b) {
return $a + $b;
}
function greet($name) {
echo "Hello, " . $name . "<br>";
}
然後,在另一個檔案中,可以使用 require
或 include
語句導入模組:
require "my_module.php";
$result = sum(3, 5);
echo "3 + 5 = " . $result . "<br>";
greet("Alice");
9. C# 語言
using System;
public class Program {
public static int sum(int a, int b) {
return a + b;
}
public static void Main(string[] args) {
int result = sum(3, 5);
Console.WriteLine("3 + 5 = " + result);
}
}
C# 使用命名空間來表示模組。例如,一個名為 MyModule
的命名空間可以包含以下程式碼:
namespace MyModule {
public static class MathUtils {
public static int sum(int a, int b) {
return a + b;
}
}
public static class Greetings {
public static void greet(string name) {
Console.WriteLine("Hello, " + name);
}
}
}
然後,在另一個檔案中,可以使用 using
語句導入模組:
using System;
using MyModule;
public class Program {
public static void Main(string[] args) {
int result = MathUtils.sum(3, 5);
Console.WriteLine("3 + 5 = " + result);
Greetings.greet("Alice");
}
}
10. Ruby 語言
def sum(a, b)
return a + b
end
result = sum(3, 5)
puts "3 + 5 = #{result}"
Ruby 使用檔案來表示模組。例如,一個名為 my_module.rb
的檔案可以包含以下程式碼:
module MyModule
def self.sum(a, b)
return a + b
end
def self.greet(name)
puts "Hello, #{name}"
end
end
然後,在另一個檔案中,可以使用 require
語句導入模組:
require "my_module"
result = MyModule.sum(3, 5)
puts "3 + 5 = #{result}"
MyModule.greet("Alice")
1. 陣列 (Array)
定義: 陣列是一種線性資料結構,用於儲存相同資料類型的元素的集合。陣列中的元素以連續的記憶體位置儲存,並使用索引 (index) 來存取它們。索引從 0 開始,到陣列大小減 1 結束。
特點:
應用:
2. 串列 (List)
定義: 串列是一種線性資料結構,用於儲存資料元素的順序集合。串列中的元素可以是任何資料類型,並且可以動態新增或刪除。
特點:
應用:
3. 堆疊 (Stack)
定義: 堆疊是一種後進先出 (LIFO) 的資料結構。它就像一個堆疊的盤子,最後放上去的盤子會最先被拿走。
特點:
push
)或刪除元素(稱為 pop
)。應用:
4. 佇列 (Queue)
定義: 佇列是一種先進先出 (FIFO) 的資料結構。它就像排隊等候的人群,最先排隊的人會最先被服務。
特點:
enqueue
)。dequeue
)。應用:
5. 樹 (Tree)
定義: 樹是一種非線性資料結構,由節點 (node) 組成,節點之間以父子關係連接。樹的根節點沒有父節點,而葉節點沒有子節點。
特點:
應用:
6. 圖 (Graph)
定義: 圖是一種非線性資料結構,由節點 (node) 和邊 (edge) 組成。節點表示物件,邊表示節點之間的關係。
特點:
應用:
7. 集合 (Set)
定義: 集合是一種資料結構,用於儲存不重複的元素。集合中的元素沒有順序,並且可以是任何資料類型。
特點:
應用:
以下是不同程式語言中資料結構的表示方式,涵蓋常見的資料結構與範例:
1. 陣列 (Array)
int arr[5];
// 宣告一個大小為 5 的整數陣列int[] arr = new int[5];
// 宣告一個大小為 5 的整數陣列arr = [1, 2, 3, 4, 5]
// 宣告一個包含 5 個元素的整數列表let arr = [1, 2, 3, 4, 5];
// 宣告一個包含 5 個元素的整數陣列arr := [5]int{1, 2, 3, 4, 5}
// 宣告一個大小為 5 的整數陣列2. 串列 (List)
std::list
模板類別java.util.List
接口,例如 java.util.ArrayList
list = [1, 2, 3, 4, 5]
// 使用列表表示串列let list = [1, 2, 3, 4, 5];
// 使用陣列表示串列[]int
切片表示串列3. 堆疊 (Stack)
std::stack
模板類別java.util.Stack
類別append()
和 pop()
方法模擬堆疊push()
和 pop()
方法模擬堆疊[]int
切片,並使用 append()
和 pop()
方法模擬堆疊4. 佇列 (Queue)
std::queue
模板類別java.util.Queue
接口,例如 java.util.LinkedList
append()
和 pop(0)
方法模擬佇列push()
和 shift()
方法模擬佇列[]int
切片,並使用 append()
和 pop(0)
方法模擬佇列5. 樹 (Tree)
std::map
或 std::set
模擬樹java.util.TreeMap
或 java.util.TreeSet
模擬樹Map
或 Set
模擬樹map
模擬樹6. 圖 (Graph)
std::map
或 std::set
模擬圖java.util.HashMap
或 java.util.HashSet
模擬圖Map
或 Set
模擬圖map
模擬圖7. 集合 (Set)
std::set
或 std::unordered_set
模板類別java.util.Set
接口,例如 java.util.HashSet
或 java.util.TreeSet
set
資料類型Set
資料類型map
模擬集合,或者使用 set
包範例:
# 陣列
numbers = [1, 2, 3, 4, 5]
# 串列
my_list = [1, 2, 3, 4, 5]
# 堆疊
stack = []
stack.append(1)
stack.append(2)
stack.pop()
# 佇列
queue = []
queue.append(1)
queue.append(2)
queue.pop(0)
# 樹
tree = {
'root': {
'left': {
'value': 1
},
'right': {
'value': 2
}
}
}
# 圖
graph = {
'A': ['B', 'C'],
'B': ['A', 'D'],
'C': ['A', 'E'],
'D': ['B'],
'E': ['C']
}
# 集合
my_set = {1, 2, 3, 4, 5}