Data types - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Data types (/thread-762.html) |
Data types - tahmid909 - Nov-03-2016 Just a quick question, i've wrote a piece of code that analyses a sentence that contains several words without punctuation. When a word in that sentence is input, the program identifies all of the position the word occurs in the sentence. In order to do this i used variable.split(' '). My question is what data type is .split(' '), i am using python. Any help would be appreciated. RE: Data types - snippsat - Nov-03-2016 Quote:My question is what data type is .split(' '), i am using python. Any help would be appreciated. It's not data type but a string method,can also be called build function. The string methods is used on datatype str(string). >>> s = 'hello world' >>> type(s) <class 'str'> >>> s.split() ['hello', 'world'] >>> help(s.split) Help on built-in function split: split(...) method of builtins.str instance S.split(sep=None, maxsplit=-1) -> list of strings Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result. RE: Data types - Skaperen - Nov-04-2016 i suggest split(None) |