Python: Variables & Data types

Today I started my python learning from the basics of the language.Started with the introduction of python, it is a versatile language, syntax is simple, the length of the code is short and easy to write code.
Variables and Data types are the basic of any language. So, I started with them.Variables are like containers for storing values. Values in the variables can be changed.
Every value or data has an associated type to it known as data type. Commonly used data types are String, Integer, Float, Boolean.
String is a set of characters enclosed within quotes. Example: "welcome to hashnode.dev", "12345", etc.
Integer represents all whole numbers(positive, negative and zero) except fractional part. Example: -3,-2,-1,0,1,2,3.....etc.
Float means any number with a decimal point. Example 2.0, 20.0,....etc.
Boolean in normal words, Anything that can take one of two possible values is known as boolean. Example: True or Flase, 1 or 2, Yes or NO. The both start with a capital as a syntax.
Sequence of intructions:
\>A variable gets created when you assign a value to it for the first time. For example a=10, here itself the the variable created when we assigned a value 10 to variable a.
\>Python executes the code line by line. For example print(a), a=10. In this case the first line executes and comes to the second line. In first line print(a) the value for a is not assinged so its the error as 'NameError'.
\>Having spaces at the beginning of the line causes error.
\>Values in the variable can be changed. If we assign a value for the variable as a=1 and we print the variable the the output will be 1. And again we assign another value to the same variable as a=2 and print that will show the output as 2.
Subscribe to my newsletter
Read articles from Nikhil Reddy Kandi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
