Assignment Statement

Python Parser shares the same syntax with Python in basic assignment, tuple assignment, sequence assignment, sequence unpacking, and augmented assignment (+=, -=, &=, |=,*=, /=, **=, %=)... Python Parser currently does not support list assignment and chained assignment.

Basic Assignment

a=10
print(a)

Output: 10

Tuple Assignment

a,b=11,12
print(a)

Output: 11

Sequence Assignment

x, y, z = "Orange"
print(x)

Output: Orange

print(y)

Output: Orange

print(z)

Output: Orange

Sequence Unpacking

a, *b = 'Orange'
print(a)

Output: Orange

print(b)

Output: Orange

Augmented Assignment

a = 42
a *= 3
print(a)

Output: 126

List Assignment (Unsupported)

[a,b]=[1,2]

Chained Assignment (Unsupported)

x = y = z = "Orange"

Changing Items in a Nested List

Changing a specific item in a nested list through multiple indices is not supported. Take line #2 in the following script as an example, DolphinDB will convert a[1][1] to a[1,1], which cannot be taken as an index to access an item in Python.

a=[2, [3, 5], 10]
a[1][1]=19

Output: Assignment statement failed probably due to invalid indices [a[1,1] = 19]

// Assign an index of the nested list to the variable temp and change the item value of this variable:
tmp=a[1]
tmp[1]=19
a

Output: [2, [3, 19], 10]

Releasing Variables

The undef function is used to release variables from the memory.

x=1;
undef(`x)
def max(a, b):
    if a > b:
        return a
    else:
        return b
undef(`max)