我工作在PyCharm分配,並一直負責下列問題:在Python中使用字符串切片來查找字符串前半部分的長度?
的LEN()函數用來計算一個字符串多少個字包含的內容。獲取字符串的前半部分,存儲在變量「phrase」中。
注意:記住類型轉換。
這裏是我到目前爲止的代碼,它給了我:
phrase = """
It is a really long string
triple-quoted strings are used
to define multi-line strings
"""
first_half = len(phrase)
print(first_half)
我不知道該怎麼做。我需要使用字符串切片來查找字符串「phrase」的前半部分。任何幫助讚賞。我爲我的無知道歉。
如果我有一個三明治的長度是12英寸,我切片6英寸,我有什麼? –
那麼奇數字母的字符串呢? – Sasha
first_half = len(短語)/ 2獲得半長度,我認爲你使用的是python3,你必須使用'// 2'這就是他們正在談論的類型轉換 – The6thSense