Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字符串的join方法的作用是什么,使用join应该注意些什么,请举例说明 #59

Open
Sogrey opened this issue Feb 16, 2020 · 0 comments

Comments

@Sogrey
Copy link
Owner

Sogrey commented Feb 16, 2020

dirs = '','usr','local','nginx',''
print(dirs)  ## ('', 'usr', 'local', 'nginx', '')
linuxPath = '/'.join(dirs) 
print(linuxPath)   ## /usr/local/nginx/
windowPath = 'C:' + '\\'.join(dirs)  
print(windowPath)  ## C:\usr\local\nginx\

num = [1,2,3,4,5]
print(s.join(num))  ## TypeError: sequence item 0: expected str instance, int found   列表中元素须为字符串

join方法可以将列表中的字符串类型元素值连接起来,并且可以指定元素值直接的分隔符。

@Sogrey Sogrey added this to 正则表达式 in Python QAs Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Python QAs
正则表达式
Development

No branches or pull requests

1 participant