concatenate函数怎么用python(函数concatenate的用法)

admin 192 0

大家好,感谢邀请,今天来为大家分享一下concatenate函数怎么用python的问题,以及和函数concatenate的用法的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!

一、Python中怎么把list转换为字符串

1、List中存的是字符串的时候,一般是通过join()函数去转换:

2、 dataList= ['1','2','3','4' ]

3、join()是一个字符串方法,它返回被子字符串连接的字符串。

4、参数:The join() method takes join()方法需要可迭代的元素来一次返回它的一个成员,比如列表,元组,字符串,字典和集合

5、返回值:join()方法返回一个被子字符串连接的字符串。

6、Type Error:如果这个可迭代元素包含任何不是字符串的值,join()函数就会抛出TypeError。

二、python的sum函数怎么用

1、sum(iterable[, start]),iterable为可迭代对象,如:

2、sum([ ], start)#iterable为list列表

3、sum((), start)#iterable为tuple元组

4、最后的值=可迭代对象里面的数相加的值+ start的值

5、start默认为0,如果不写就是0,为0时可以不写

6、即sum()的参数最多为两个,其中第一个必须为iterable,例如:

7、>>> sum([1, 2, 3,], 4)

8、如果你写成sum([1,2,3]),start就是默认值 0

9、当然iterable为dictionary字典时也是可以的:

10、>>> sum({1:'b', 7:'a'})

11、>>> sum({1:'b', 7:'a'}, 9)

12、下面这些写法目前是不被接受的(以list为例,其他iterable同理):

13、Traceback(most recent call last):

14、 File"<pyshell#115>", line 1, in<module>

15、TypeError: can only concatenate list(not"int") to list

16、Traceback(most recent call last):

17、 File"<pyshell#116>", line 1, in<module>

18、TypeError:'int' object is not iterable

19、Traceback(most recent call last):

20、 File"<pyshell#117>", line 1, in<module>

21、TypeError: sum expected at least 1 arguments, got 0

22、Traceback(most recent call last):

23、 File"<pyshell#112>", line 1, in<module>

24、TypeError:'int' object is not iterable

25、Help on built-in function sum in module builtins:

26、 sum(iterable[, start])-> value

27、 Return the sum of an iterable of numbers(NOT strings) plus the value

28、 of parameter'start'(which defaults to 0). When the iterable is

OK,本文到此结束,希望对大家有所帮助。