Variables and Data types in Python

Python is an all-rounder programming language which deals with several types of basic fundamentals, these are going to use to develop Python programs which include variable, identifiers, data types, strings arrays, etc..

Let us understand one by one as follow:

Python Identifiers:

A name which represents Variable, class, Function, Method name or Object which is used for identification purpose is called as Identifier

  • Identifiers can be in Lowercase(a to z),
  • Uppercase(A to Z), and digits(0 to 9)
  • It can be an Underscore( _ )

Ex: valid examples

 myClass
 classTest
Num_1 

Invalid examples

1_var
ca$h=10

Just see the below example

python-identifier-error

Some Rules for Python Identifiers :

  • Where the identifier does not include any special characters like $,%,&, *,etc..
  • Identifier names never start with Digits
    identifier-never-starts-with-digits
  • Python Identifiers are the case sensitive
    case-sensitive-identifier
  • There is no length limit for Python Identifiers
    identifier-no-lenght-limit
  • Even though there is no length limit for identifiers we should not use unnecessarily too lengthy identifiers
  • In Python there are some reserved words are there which we cannot use to declare the variables
    identifiers-reserved-words
  • If any variable starts with _x is called a protected variable
  • If any variable starts with two underscores __x is called a private variable
  • If any variable starts with two underscores and ends with two variables is called as Magic variable __x__

Python keywords :

The words which are used to represent the syntax and Structure of the python language is called as Keywords or Python Reserved words.

  • Keywords are case sensitive
  • there are 33 keywords in Python language
  • All the keywords except True, False and None are in the lowercase

The list of Keywords are as follows :

False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise
  • All the keywords contain only alphabet symbols
  • let us see some examples:
true-error

  • Python is a dynamically typed language and hence it does not require any int, float, complex type of reserved words.
  • There is a keyword module in Python, we can import them as shown below:

    import keyword
    keyword.kwlist​

    If you enter the above command it will list out all the keywords which are present in the keyword module

    kw-list

Introduction to Python Datatypes

Data type: It represents the type of data stored in a variable which is used in our program is called as Datatype.

Python is a Dynamically typed programming language and hence we are not required to define the types of the Data explicitly

Based on the assigned value the type will be considered by the python virtual machine, and also there will be a function called type(a) which represent the data type of a.

example:

  • Int type
a=10
data-type-int

  • Boolean type
b=True​
data-type-boolean

  • Float type
    c=10.5​
    data-type-float

Different data types available in Python

There are 14 types of Data types are present in the Python

1

int

2 float
3 complex
4 boolean
5 string
6 list
7 tuple
8 set
9 frozenset
10 dict
11 bytes
12 bytes array
13 range
14 none
Note: Everything in the Python is an Object

There are three inbuilt functions are there in the Python :

Consider an example where we are assigning a value to an a=10

  • And if we want to know the type of a, we will use type(a) and then it will display the data type of a
  • And if we want to know the address of a that means where it is located then we will use id(a)
  • And if we want to print the value of a, we will use print(a)
    a=10
    type(a)
    id(a)
    print(a)​
inbuilt-functions

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

U