list, sequence of mutable values, or values we can change
like arrays in C, can grow and shrink automatically in Python
tuple, collection of ordered values like x- and y-coordinates, or longitude and latitude
dict, dictionaries, collection of key/value pairs, like a hash table, constant time: O(1)
1 2 3 4 5 6 7 8 9
from cs50 import get_string people = { "Tom": "tom@123.com", "Mary": "mary@123.com" } name = get_string("name:") # type "Tom" if name in people: print(f"Email: {people[name]}") #Email:tom@123.com
set, collection of unique values, or values without duplicates
Examples
1 2 3 4
from cs50 import get_string
answer = get_string("What's your name?") #type "Tom" print(f"Hello, {answer}") #Hello, Tom
f: format string,可以在字串裡使用變數,變數需要使用 {}
每一行的最後面可以不打 semicolon
變數前不用宣告 data type,type 由數值定義,python 是 loosely type 的語言。