.github
api-server
client
config
curriculum
docs
guide
arabic
chinese
english
3d
accessibility
agile
algorithms
android-development
angular
angularjs
apache
aspnet
bash
blender
blockchain
bootstrap
bsd-os
bulma
c
canvas
certifications
chef
clojure
cloud-development
computational-genomics
computer-hardware
computer-science
containers
cplusplus
csharp
css
d3
data-science-tools
design-patterns
designer-tools
developer-ethics
developer-tools
devops
docker
documentation
drupal
electron
elixir
elm
erlang
fsharp
game-development
gatsbyjs
git
go
groovy
haskell
haxe
hibernate
html
ionic
java
javascript
joomla
jquery
julia
kotlin
laravel
linux
logic
machine-learning
mathematics
meta
miscellaneous
mobile-app-development
mongodb
natural-language-processing
neovim
network-engineering
nginx
nodejs
optical-alignment
php
product-design
progressive-web-apps
puppet
python
abs-function
all-iterable
anaconda
any-iterable
args-variable
basic-operators
bool-function
boolean-operations
built-in-constants
calling-functions
class
code-blocks-and-indentation
commenting-code
comparisons
complex-numbers
containers
converting-integer-to-string-in-python
creating-guis-in-python3
data-structures
decorators
defaultdict
defining-functions
difference-between-is-and-equal-equal-operators
docstring
escape-sequences
exception-and-error-handling
files-and-io
for-loop-statements
from-x-import-y
frozenset
functions
generators
hex-functions
how-to-convert-strings-into-integers-in-python
idobject
if-elif-else-statements
import-statements
input-functions
installing-and-using-python-3
is-there-a-way-to-substring-a-string-in-python
iterators
itertools
keywords
lambda-expressions
learn-about-python-sets
len-function
list-deque
lists
max-function
min-function
more-built-in-types
mutability-and-variable-assignments
name-binding-and-aliasing-functions
nested-functions
numeric-operations
numeric-types
object-oriented-programming
ord-function
parenthesis-for-boolean-operations
powxy
python-2-vs-python-3
python-coding-standards
python-f-strings
python-resources
range-function
raspberry-pi-basics
rest-api-with-falcon
return-statement
sequence-types
set-types
setting-up-python-web-framework-django-and-flask
share-file-using-python-simple-http-server
sleep-how-can-i-make-a-time-delay-in-python
slicestartstopstep
string-methods
string-find-method
string-join-method
index.md
string-replace-method
string-split-method
string-strip-method
index.md
ternary-operator
truth-value-testing
using-pip
using-python-for-web-development
variable-names-and-binding
virtual-environments
web-frameworks-and-what-they-do-for-you
what-is-python-used-for
while-loop-statements
zip-function
index.md
r
raspberry-pi
react
react-native
redux
rest-api
robotics
rt-os
ruby
rust
sass
security
semantic-ui
software-engineering
sql
ssh
svg
svn
swift
terminal-commandline
tomcat
tools
typescript
typography
user-experience-design
user-experience-research
vagrant
vim
virtualbox
visual-design
voice
vue
vue-cli
web-augmented-reality
web-components
web-performance
web-virtual-reality
wordpress
working-in-tech
xml
portuguese
russian
spanish
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README(french).md
README-IT
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
61 lines
1.2 KiB
Markdown
61 lines
1.2 KiB
Markdown
![]() |
---
|
||
|
title: String Join Method
|
||
|
---
|
||
|
## String Join Method
|
||
|
|
||
|
The `str.join(iterable)` method is used to join all elements in an `iterable` with a specified string ```str```.
|
||
|
If the iterable contains any non-string values, it raises a TypeError exception.
|
||
|
|
||
|
`iterable`: All iterables of string. Could a list of strings, tuple of string or even a plain string.
|
||
|
|
||
|
#### Examples
|
||
|
|
||
|
1) Join a ist of strings with `":"`
|
||
|
```python
|
||
|
print ":".join(["freeCodeCamp", "is", "fun"])
|
||
|
```
|
||
|
Output
|
||
|
```shell
|
||
|
freeCodeCamp:is:fun
|
||
|
```
|
||
|
|
||
|
2) Join a tuple of strings with `" and "`
|
||
|
```python
|
||
|
print " and ".join(["A", "B", "C"])
|
||
|
```
|
||
|
Output
|
||
|
```shell
|
||
|
A and B and C
|
||
|
```
|
||
|
|
||
|
3) Insert a `" "` after every character in a string
|
||
|
```python
|
||
|
print " ".join("freeCodeCamp")
|
||
|
```
|
||
|
Output:
|
||
|
```shell
|
||
|
f r e e C o d e C a m p
|
||
|
```
|
||
|
4) Joining with empty string.
|
||
|
```python
|
||
|
list1 = ['p','r','o','g','r','a','m']
|
||
|
print("".join(list1))
|
||
|
```
|
||
|
Output:
|
||
|
```shell
|
||
|
program
|
||
|
```
|
||
|
5) Joining with sets.
|
||
|
```python
|
||
|
test = {'2', '1', '3'}
|
||
|
s = ', '
|
||
|
print(s.join(test))
|
||
|
```
|
||
|
Output:
|
||
|
```shell
|
||
|
2, 3, 1
|
||
|
```
|
||
|
|
||
|
#### More Information:
|
||
|
<a href='https://docs.python.org/2/library/stdtypes.html#str.join' target='_blank' rel='nofollow'>Python Documentation on String Join</a>
|