samedi 9 février 2019

python string split method, with only integer argument, no delimiter is used

import unittest

class TestStringMethods(unittest.TestCase):

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split fails when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)

if __name__ == '__main__':
    unittest.main()

what is the use of s.split(2) method? what author wants to accomplish from this code. what split method of string module do when it is call using only integer argument?

Aucun commentaire:

Enregistrer un commentaire