stykzman wrote:DarkFlame wrote:ok nevermind, I found how to do it in Python:
- Code: Select all
import string
words = string.split("Hello World!")
len(words)
The output would be:
- Code: Select all
2
Cool... it looks like you don't need to provide a character to split on; Python assumes a space unless you provide a delimiter, right?
i'm pretty sure, i don't remember how to add that parameter, i think you just add it as an optional second string in the parenthises.
EDIT: I could break it down to two lines like so:
- Code: Select all
>>> import string
>>> len(string.split("Hello World!"))
2
>>>
EDIT2:
An new example: writing to and reading from a file
- Code: Select all
file = open("filename.txt", "w")
file.write("Hello World!/n This is a new line")
file.close()
file = open("filename.txt", "r")
file.read()
And the output would be:
- Code: Select all
Hello World!
This is a new line


