Basics of Object & Datatypes for PYTHON
Data types are the basic building blocks of larger piece of codes.
In this article, we will have an overview of all the basic data types in python and then we will go into details of all the data types
Let’s begin with the first data type Numbers (Integers and Floating point).
Python has various types of numbers: plain integers, long integers, floating point numbers and complex numbers. We’ll mainly focus on plain integers and floating point numbers.
Integers are just whole numbers, positive or negative: 5 or -5 are examples of integers.
Floating point numbers have a decimal in them or an exponential (e): 5.2 or -5.2 and 6e2 (6 times 10 to the power 2 (6 x 102)).
Let’s start with some basic arithmetic:
Multiplication and Division
In normal division we use / (single forward slash) operator and get the result as floating point number in cases such as above.
But in floor division, where // (double forward slash) operator is used, the result we get is an integer value. This is because this operator removes truncates the decimal without rounding off.
This operator returns the remainder after division.
Python follows all the basic arithmetic rules of operation.
The following rules are to be followed when giving a name to a variable:
- Names cannot start with a number.
- No spaces can be used in a name, use _ instead.
- No special characters: ~!@#$%^&*(),<>?”’-+*
- Avoid using words like: ‘list’, ‘int’, ‘str’, ‘set’, that have special meaning in python.
- It’s considered best that variable names are lowercase.
For assigning a value to a variable we use single equals sign (=). Let’s see a few examples:
Re-assigning and over writing a variable
In this article we have learned about numbers, performing basic arithmetic operation with numbers and variable assignment.
Next we will learn about Strings in python.
Till then good bye…………