Title: Breaking Up String Variables
Slug: breaking_up_string_variables
Summary: Breaking Up String Variables
Date: 2016-05-01 12:00
Category: Python
Tags: Basics
Authors: Chris Albon

Basic name assignment


In [15]:
variableName = 'This is a string.'

List assignment


In [16]:
One, Two, Three = [1, 2, 3]

Break up a string into variables


In [17]:
firstLetter, secondLetter, thirdLetter, fourthLetter = 'Bark'

In [18]:
firstLetter


Out[18]:
'B'

In [19]:
secondLetter


Out[19]:
'a'

In [20]:
thirdLetter


Out[20]:
'r'

In [21]:
fourthLetter


Out[21]:
'k'

Breaking up a number into separate variables


In [22]:
firstNumber, secondNumber, thirdNumber, fourthNumber = '9485'

In [23]:
firstNumber


Out[23]:
'9'

In [24]:
secondNumber


Out[24]:
'4'

In [25]:
thirdNumber


Out[25]:
'8'

In [26]:
fourthNumber


Out[26]:
'5'

Assign the first letter of 'spam' into varible a, assign all the remaining letters to variable b


In [27]:
a, *b = 'spam'
a


Out[27]:
's'

In [28]:
b


Out[28]:
['p', 'a', 'm']