Lists in Python
In this articles, we will look to Tuple variables in Python.
In earlier article, print methods of variables and variables, we saw that variables are memory locations to keep values. When a variable declared in Python, a space is allocated in memory. Then interpreter takes memory and decides what can be stored in the memory area. We can store integers, decimals or char acters in the variables we declare in Python. In Python variables do not need an explicit declaration to for memory space. The declaration is automatic when we create and assign a value to a variable. The equal sign = is used to assign values to variables.
Tuples are a compund type variable similar to C, C++ and C# arrays but can store different type of variables like int, string and others.
Difference between lists and tuples are: lists are can get update, tuples are read-only.
Lists are declared as follows:
list_planetInfo=[100,"mercury"]
tuple_planetInfo=(101,"neptun")
print(list_planetInfo[0])
print(tuple_planetInfo[0])
list_planetInfo[0]=200
tuple_planetInfo[0]=201
print(list_planetInfo[0])
print(tuple_planetInfo[0])
Lets see Python tuple variables in an example.
In above example, we created a tuple variable in Python and print it to terminal.