Python variable names and number data types

sammy ilesanmi
3 min readJan 24, 2021

On my journey in python programming language, after learning how diversified python is and how it could be used for many things such as:

  1. data science
  2. automate things
  3. machine learning, and so on.

With this interest in heart, I’ll like to share what python variables are and the number data types.

Python variables

Python variables are set of containers for storing data values just as a cup holds water. Take the cup as the variable and the water as the data. A cup could also hold many other things; which still explains the data could be anything. So, a variable houses data.

For example, if my data is an integer 4. I can house the number into a variable called ‘y’.

There are basic rules which guides naming a variable, and some of these rules are:

  1. Python reserved words such as break, if, else, continue, str, int, etc — cannot be named a variable.
  2. Variables cannot start with a number
  3. A variable name must start with a letter or the underscore character
  4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0–9, and _)
  5. Variable names are case-sensitive (age, Age and AGE are three different variables)

Following this rules guides one to the names we wish to give our variables.

Lastly on naming variables, whenever the names of our variables goes beyond one word, there are techniques that can be used to name them. Some of these techniques are:

  1. Camel case

Camel case is written such that each word aside the first starts with a capital letter.

e.g. myDateOfBirth = 2045

2. Pascal case

Pascal case is written such that each word starts with a capital letter.

e.g. MyDateOfBirth = 3045

3. Snake case

Snake cas is written such that each word is separated by an underscore character.

e.g. my_date_of_birth

Also, there’s a possible way of assigning multiple variables.

For example, suppose I want to different kinds of fruit to different variables, there’s a shorter method which is shown thus:

x,y,z = ‘banana’, ‘pineapple’, ‘cashew’

Python automatically assign this data rightly to their respective variable respectively.

Isn’t python beautiful? 😁😁

Now, the number data types.

python has built in data types. And some of these are grouped into the following:

  1. Text types.
  2. Numeric types.
  3. sequence types.

4. Boolean types, and so on

I’ll write a little on the Numeric data type. The Numeric data type houses the integer, float and the complex data. This data types are numbers related.

The integer data type — An integer is any number that is not either a decimal or a fraction. It could be negative or positive. It’s abbreviated to be int

examples of integers are 0, -1, 1,-2, 2, 3, -4,…

The float data type — Float data type are just Decimal numbers. Also, they could be negative or positive.

Examples of float are 1.2, 2.3, 4.2, 5.7, …

The complex data type — Complex numbers are numbers written with the letter i or j in it. where i or j represents the square root of (-1).

Examples of these numbers are 1+1j, 2+3j, …

These are the Numeric data types in python. Hope something was learnt?

Just to add, if there’s need to confirm the data type of a data, just write type( ). You put the data inside the parameters.

A practical example is:

type(1) will return int.

type(1.2) will return float;

And so on.

To note once again, this article and the learning is a courtesy of GemMine. And the name of my facilitator and mentor is Sir Promise Shittu.

Thank you Sir Shittu, and thank you GemMine.

Thank you readers.👍

--

--