Data Types and Variable

 

Data Types and Variable

 

As already discussed, the Character Set followed by Python Language is ASCII , so Python is a Case Sensitive Language. Now let's further discuss on the next step, that is learning Words in Python.

 

Keyword Set

 

The Keyword set are in Limited numbers in any Language. As of now, in Python 3.8 there are 35 keywords. As the Language is getting evolved, there is chances of few keywords getting added whenever RELEASE  or VERSION changes.

 

 

Current Keyword Set

 

False   await  else  import  pass None  break except in  raise  True  class finally  is  return  and  continue  for  lambda  try  as  def  from  nonlocal  while assert  del  global  not  with  async  elif  if  or  yield

 

Keywords are case sensitive so use them as given only.

 

Data Types

 

The Language supported Data Type will vary from Language to Language , some may have only a few like in C Language there are only 4 types, which are called Primitive Data Types. But in python there are no Primitive Data Types. All Data are considered as Objects only, therefore instead of Data Types, it is Data Classes in Python. That is the Data are Instances or Objects under these Data Classes.

 

Python requires no explicit declaration and the Interpreter automatically detects the type of Data, based on the value provided. There are in-built Data Classes available, they are,

 

1.String used to store Text Data. It can be a single character or multiple ones, everything is considered as String only. There is no separate Character data type.

 

2.Number Numeral values are considered as Number Data. In Python it can be whole Numbers like integer, Floating Point Numbers like float and Complex Numbers where the Number contains 2 parts Real and Imaginary.  We can even represent Fractions in Python and process them if we include the Python Fraction module. The memory size for Integer or Float is not fixed as in other Languages.

It is solely depends on the System Memory Size. So we can store and process how much ever  Big Numeric Data.

 

3.Boolean :

This can save , either True or False values.

 

4.Sequence:

This can save multiple Data each separated by comma under a Single Name. There are few inbuilt sequence types available in Python they are

 

a.Tuple - Multiple values enclosed within () parenthesis. They are immutable, means the individual values of Tuple cannot be changed.

 

b.List - Mutiple values enclosed within [] square brackets. They are mutable, means the individual values of List can be changed.

 

c. Range - A continuous set of Numbers, normally used in Loop Statements.

 

5. Mapping Type : This can save multiple values as a Pair.

a. Dict - Multiple values in pairs enclosed within  {} curly braces. A Pair of Key and Values are saved.

 

6. Set Type : A Set of related values like in Mathematics.

 

a. Set - Multiple values enclosed within {} curly braces. They are mutable and unique values.

 

b. Frozen Set - Multiple values enclosed within {} curly braces. They are immutable and unique values.

 

7.Binary Types: Values stored in form of Bytes

 

a. Bytes - a Data is converted to its Byte Form. It is immutable.

b. Byte Array - Same as Bytes but the difference is it is mutable one.

c. Memory view - It is a way of accessing the Internal Buffer as an Object. That is how a Data is stored in the Memory can be viewed.

 

8.None Type : Null Data Type.

a. None - Since all the Data type are of the Object types, we can set any Object to Null at any time. In Python, None keyword is an object and any Data variable that is set to None will point to this object only. That is new Instance is not created.

 

Type Function

 

The type() function can be used to verify the Data class of the variable / data.

 

If you check the data type of x with the statement print(type(x)) from shell window we can view the following.

 

Example

Data Type

x="Hello World"

str

x=20

int

x=20.5

float

x=5+1j

complex

x=["apple","banana","cherry"]

List

x=("apple","banana","cherry")

Tuple

X=range(6)

Range

X={"name":"john","age":36}

Dict

X={"apple","banana","cherry"}

Set

X=frozenset({"apple","banana","cherry"})

Frozenset

X=True

Bool

X=b"Hello"

bytes

X=bytearray(5)

bytearray

X=memoryview(bytes(5))

memoryview

X=None

NoneType

 

Variables

 

Variables are used as placeholders for a Data, where we substitute the Variable with actual Data while running the Program. This is similar to Algebra in Mathematics, where instead of values we will be using characters. So these are the Names for the Data. But the Naming of any variable should follow these Rules.

 

]A variable Name can contain Alphabets, Numerals and Underscore.

]No other Special Characters are allowed, including whitespace.

]A variable name should begin either with an Alphabet or Underscore. Numeral is not allowed.

]A Keyword or Reserved word cannot be used as a Variable Name

 

 

No comments:

Post a Comment