Splitting up words by spaces is such a common task in computer science
that Python has a built-in function, string.split(), that does just that.
For example, suppose we take one of Charlotte Bronte's books as a string
and we call split on it.
We'll get out a list where each element of the list corresponds
to one of the words in this string separated by spaces.
This space here leads us directly to this comma, separating these list elements.
Let's take a moment now to get a little more practice with this new approach
to splitting by whitespace.
Whitespace is just a more formal name for some series of spaces or tabs.
Here I've written three Python expressions, each one of which is a constant string.
We're calling split on it.
I'd like you to fill in each box with the number of elements in the list returned
by the split expression.
You can use the interpreter if you like, but try to reason it out no your own.
Selezionare parole tramite gli spazi è un compito talmente comune in Informatica
che Python possiede un metodo integrato (built-in): string.split().
Per esempio, supponiamo di avere come stringa il titolo di un libro di Charlotte Bronte
e di richiamare su di essa la funzione split().
Riceveremo una lista dove ogni elemento corrisponde
ad ognuna parola separata da uno spazio nella stringa.
Questo spazio qui è seguito da una virgola, che separa questi elementi della lista.
Prendiamoci ora un momento per impratichirci con questo nuovo approccio
che permette di separare tramite spazi bianchi.
Lo spazio (whitespace) è solo un nome formale per questa serie di spazi o tab.
Ho scritto qui tre espressioni in Python, ognuna delle quali è una stringa.
Richiameremo il metodo split() su di loro.
Vorrei che completaste ogni quadrato con il numero di elementi della lista risultante
dalle espressioni split().
Puoi usare l'interprete se vuoi, ma prova prima a ragionare da solo.
単語をスペースで分けることは
コンピュータ・サイエンスではよく行われます
Pythonにはこれを実行する
string.split関数が組み込まれています
例えばシャーロット・ブロンテの小説
“Jane Eyre”を文字列として使い
split関数を呼んでみます
まずリストが戻り値として返されて
このリストの要素はそれぞれ
スペースで区切られた文字列にある単語に
符合します
このスペースはこのカンマに置き換えられ
リストの要素を分けています
では少し時間をとって
ホワイトスペースによる分割という
新しいアプローチを練習してみましょう
ホワイトスペースとは
スペースやタブなどのフォーマルな言い方です
ここで3つのPython表現を書きました
どれも定数文字列です
split関数を呼び出します
split関数によって返ったリストにある要素の数を
各ボックスに入れてください
インタプリタを使ってもいいですが
まずは自力で解いてみてください
Separar palavras por espaços é uma tarefa tão comum em computação,
que Python provê uma função built-in string.split(), para fazer exatamente isso.
Por exemplo, suponha que tomamos como string o texto de um dos livros de Charlote Bronte
e chamamos split com esse argumento.
Vamos obter uma lista, em que cada elemento corresponde
a uma das palavras desse string, separadas por espaços.
Esse espaço aqui corresponde a essa virgula, separando esses elementos da lista.
Vamos praticar um pouco mais essa nova abordagem
de separação de palavras.
whitespace significa uma série de espaços ou tabs.
Aqui, temos algumas expressões Python, sendo cada qual uma constrante de tipo string.
Chamamos split sobre cada uma.
Preencha cada um dos quadros com o número de elementos da lista retornada
pela expressão.
Você pode usar o interpretador, se quiser, mas tente raciocinar diretamente.
Despartirea cuvintelor prin spatii e o
cerinte banala in stiinta calculatoarelor
asa incat Python are o functie
pre-instalata,string.split(), ce face asta
De exemplu, presupunem ca ca luam o carte
de-a lui CHarlotte Bronte ca string
si o impartim cu ea.
Vom obtine o lista in care fiecare element
corespunde unui
cuvant din string, separat de spatii.
Spatiul de aici duce la o virgula ce
separa aceste elemente.
Sa acordam un moment practicii noii
metode
prin impartirea prin whitespace.
Whitespace e un nume formal pentru niste
serii de spatii sau taburi.
Aici am scris 3 expresii Python, fiecare
fiind un string constant.
Aplicam split pe ele.
As vrea sa umpli fiecare casuta cu numarul
de elemente din lista rezultata
de expresia split.
Poti folosi interpretul daca vrei, dar
incearca sa o gandesti singur.
在计算机科学里,拆分空格隔开的单词是很常见的任务
以至于Python有个内置函数,string.split(),用来执行这样的操作
例如,假设我们将Charlotte Bronte的一本书名作为字符串
我们调用split函数对它进行处理
我们将得到一个列表,里面的每个元素都是
该字符串里由空格隔开的单词
这里的空格直接将我们引导到这个逗号,将列表里的元素隔开
让我们花点时间来对这个用空白字符拆分的新方法
做点练习
空白字符只是对空格或制表符的一个稍微正式点的名字
这里我写了三个Python表达式,每一个都是常量字符串
我们将调用split函数来操作
我想你们在每个框里填写
由split表达式返回的列表里的元素的个数
如果你需要,你可以使用解释器,但尽量靠你自己解决