Sunday, October 2, 2016

Python Variable Types

In last post “How To Start With Python For SDN” gives clear direction how to start with Python. In this post I am trying to cover the basic variable types which are must to know for every network engineer who wants to learn Python.

Variables are used to store values in specific memory locations. It means whenever you create a value python reserves some space in memory. Memory allocation happens based on the defined variable type. In Python we have different type of variables as given below:
1. Integer
2. Float
3. String
4. Tuple
5. List
6. Dictionary

Declare the name of the variable and use the assignment operator = to assign the value. We do not declare the variable type. The value assigned to the variable determines the type Integer, Floats, String, Lists, Dictionaries, and more types.

Let’s understand this with the help of below example. We have define a variable called ip_address and assign “” in double quotes. Now by typing type(ip_address) function help us to understand that the declared variable ip_address is of string type.

The same way we can declare the integers types by not putting them in quote as per below output.

List is collection of items, items are ordered, separated by commas and enclosed with in square brackets.

The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1.

Will cover more in the upcoming posts.

People who read this post also read :

No comments: