Python Identifiers Keywords Variables Datatypes

Identifiers and Keywords in Python

In Python any variable, function, class, module and object are identified using a name which is called as identifier. An identifier can start with uppercase or lowercase character or an underscore (_) followed by any number of underscores, letters and digits. All identifiers in python are case sensitive.

Example : weight=10

In the above example weight is an identifier.

Keywords are the reserved words in python. So keywords cannot be used as an identifier and to name variables or functions. Few of the keywords are listed below.

Example : if, else, elif, for, where, break, continue

Variables and datatypes in Python

Variables are like containers for data (i.e. they hold the data) and the value of variable can vary throughout the program.

Declaring a variable:

Syntax
Syntax: var_name = literal_value

where var_name is the name given to container which holds the value specified as literal_value

Example: weight=10

In the above example, weight is the container which holds the value 10 which can change during execution of the program.

Python may have data belonging to different types. Common data types used in programming are:

Category Datatype Example
Numeric int
long
123
1237126381763817
Numeric with decimal point float
double
123.45
123123.32345324
Alphanumeric char
string
A
Hello
Boolean boolean True, False

Python is a dynamically typed language!

In the above example, no datatype was mentioned at the time of declaring variable. In Python the datatype of a variable is decided automatically based on the value which is assigned to it, at the time of execution. This is called as dynamic typing.

Syntax
num=65 #line 1
num="A" #line 2

In line 1, variable num is assigned a value 65 which is an integer, so the data type of variable num is integer in line 1.

In line 2, variable num is assigned a value “A” which is a string, so the data type of variable num is string in line 1.

Notepad

Note : To check the datatype of the variable we can use type(var_name) which in turn returns datatype of the variable.

Program Example :

CODE/PROGRAM/EXAMPLE
num=65
	print(num,type(num))
	num=“A”
	print(num,type(num))

Output:
65 <class 'int'>
A <class 'str'>
#identifiers_in_python #python_reserved_words #reserved_keywords_in_python #python_reserved_words_list #python_keywords #Keywords_in_Python #global_keyword_in_python #super_keyword_in_python

(New page will open, for Comment)

Not yet commented...