Skip to content

Variables

Variables

In Python, variables are assigned values using the equals sign =. The equals sign = is also called the assignment operator. The statement:

a = 2

Assigns the integer 2 to the variable a. The variable a is written first, followed by the equals sign and then the value 2. When a is called at the Python REPL after it is assigned the value 2, the number 2 is returned.

>>> a = 2
>>> a
2

Multiple variables can be assigned and used in subseqent calculations.

>>> a = 3
>>> b = 4
>>> c = -1
>>> a*b*c
-12

Variables can be assigned using other variables, as long as the variables used in the assignment have been previously assigned a value.

>>> a = 2
>>> b = 3
>>> c = a + b
c

The crystalinity of a polymer can be estimated based on density according to the following relationship.

\% crystallinity = \frac{ \rho_c (\rho_p - \rho_a )}{\rho_c (\rho_p - \rho_a )} \times 100\%

given a polymer sample with a density of

\rho_c = 1.07

\rho_a = 0.987

\rho_s = 1.03

Calculate the percent crystallinity of the sample.

p_c = 1.07
p_a = 0.987
p_s = 1.03

percent_crystal = ( p_c* (p_a-p_s) ) / ( p_c*(p_a-p_s) ) * 100
percent_crystal = 56.098