Module 7 Python-Identifiers
Module 7 Python-Identifiers
PROGRAMMING
PYTHON: Identifiers, Data type, Variables, Constants,
Operators, Assignment statements and expressions
programs.
IDENTIFIERS
Variables can store data of different types, and different types can do
different things.
Python has the following data types built-in by default, in these categories:
• Lists are just like the arrays, declared in other languages which is ordered
collection of data. It is very flexible as the items in a list do not need to be of the
same type.
• Tuple is also an ordered collection of Python objects. The only difference
between tuple and list is that tuples are immutable (cannot be changed) i.e.
tuples cannot be modified after it is created. It is represented by tuple class.
• Range - range() function returns a sequence of numbers, starting from 0 by
default, and increments by 1 (by default), and stops before a specified number.
5. Set Types:
• Set – used to store multiple items in a single variable.
• Frozen set - is just an immutable version of a Python set object. While elements of
a set can be modified at any time, elements of the frozen set remain the same
after creation.
6. Boolean Type - Data type with one of the two built-in values, True or False.
Boolean objects that are equal to True are truthy (true), and those equal to False
are falsy (false). But non-Boolean objects can be evaluated in Boolean context as
well and determined to be true or false. It is denoted by the class bool.
7. Binary Types:
You can get the data type of any object by using the type() function:
In Python, the data type is set when you assign a value to a variable:
If you want to specify the data type, you can use the following
constructor functions:
CREATING VARIABLES
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
If you want to specify the data type of a variable, this can be done
with casting.
You can get the data type of a variable with the type() function.
ARITHMETIC OPERATORS
Arithmetic operators are used to perform mathematical operations like
addition, subtraction, multiplication, etc.
COMPARISON OPERATORS
Comparison operators are used to compare values. It returns either True or
False according to the condition.
LOGICAL OPERATORS
Logical operators are the and, or, not operators.
BITWISE OPERATORS
Bitwise operators act on operands as if they were strings of binary digits. They
operate bit by bit, hence the name.
In the table below: Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in
binary)
ASSIGNMENT OPERATORS
Assignment operators are used in Python to assign values to variables.
There are various compound operators in Python like a += 5 that adds to the
variable and later assigns the same. It is equivalent to a = a + 5.
MEMBERSHIP OPERATORS
Membership operators are used to test if a sequence is presented in an
object:
IDENTIFY OPERATORS
Identity operators are used to compare the objects, not if they are equal, but
if they are actually the same object, with the same memory location:
Any questions?
Nothing is impossible. The word itself says ‘I’m possible!'
— Audrey Hepburn