在 Unix 中 bash 是什麼?
請說明Python變數的設定規則
請說明Python中escape character的用法和列出常見的例子
設計程式時出現以下錯誤,請協助修正:
AttributeError Traceback (most recent call last)
<ipython-input-8-b9d8f89049c4> in <cell line: 1>()
----> 1 a.upper()
AttributeError: 'int' object has no attribute 'upper'
請Debug以下程式:
a = 235 # integer
b = "two three five" # string
c = True # boolean
d = (2, 3, 5) # tuple
e = [2, 3, 5] # list
f = {"two": 2, "three": 3, "five": 5} # dictionary
type(f)
a.upper()
請解釋以下的程式碼:
from math import log2
count_new = 0
count_york = 0
count_new_york = 0
for i,tok in enumerate(tokens):
if tok == "new":
count_new += 1
try:
next_tok = tokens[i+1]
if next_tok == "york":
count_new_york += 1
except IndexError:
pass
if tok == "york":
count_york += 1
p_new = count_new / len(tokens)
p_work = count_york / len(tokens)
p_new_york = count_new_york / len(tokens)
pmi = log2(p_new_york / (p_new * p_work))
print("p_new =", p_new)
print("p_york =", p_work)
print("p_new_york =", p_new_york)
print("pmi =", pmi)
請為以下的程式碼加上註解:
from math import log2
count_new = 0
count_york = 0
count_new_york = 0
for i,tok in enumerate(tokens):
if tok == "new":
count_new += 1
try:
next_tok = tokens[i+1]
if next_tok == "york":
count_new_york += 1
except IndexError:
pass
if tok == "york":
count_york += 1
p_new = count_new / len(tokens)
p_work = count_york / len(tokens)
p_new_york = count_new_york / len(tokens)
pmi = log2(p_new_york / (p_new * p_work))
print("p_new =", p_new)
print("p_york =", p_work)
print("p_new_york =", p_new_york)
print("pmi =", pmi)
請用Python畫出log2的圖形,並包含程式坐標軸與x=1
Remove the punctuations of a string using Python.
請改進以下程式碼:
from math import log2
count_new = 0
count_york = 0
count_new_york = 0
for i,tok in enumerate(tokens):
if tok == "new":
count_new += 1
try:
next_tok = tokens[i+1]
if next_tok == "york":
count_new_york += 1
except IndexError:
pass
if tok == "york":
count_york += 1
p_new = count_new / len(tokens)
p_work = count_york / len(tokens)
p_new_york = count_new_york / len(tokens)
pmi = log2(p_new_york / (p_new * p_work))
print("p_new =", p_new)
print("p_york =", p_work)
print("p_new_york =", p_new_york)
print("pmi =", pmi)
Please use traditional chinese in all the following response
NumPy is the fundamental package for scientific computing with Python.
May 27, 2025Also refers to official cheatsheat here
May 27, 2025Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of objects, which are instances of classes. OOP principles are fundamental concepts that guide the design and development of software in an object-oriented way. In Python, OOP is supported by the use of classes and objects. Here are some of the basic OOP principles in Python.
Apr 30, 2025An escape character is created by typing a backslash \ followed by the character you want to insert.
Apr 12, 2025or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up