S
S
Spektar_X2021-12-15 15:02:15
Python
Spektar_X, 2021-12-15 15:02:15

How to split a string into multiple variables?

variable X stores a string of three words, you want variable Y to contain the second word of the string, and variable Z the third word of the string

example:
x = "один два три"

you want variable Y to have the word "two"
and variable Z to have the word "three"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Palchevsky, 2021-12-15
@OffHand1424

Just for this case. For a different string length, a different solution is needed.

x = "один два три"

a,b,c = x.split()

print(a)
print(b)
print(c)

P
Philip Schultz, 2021-12-15
@Filipp_SC

x, y, z = 'l', 'x', 'k'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question