0% found this document useful (0 votes)
79 views

Write A Detailed Note About Datatypes and Operators in Python

Python has six main data types: numbers, strings, lists, tuples, sets, and dictionaries. Numbers can be integers, floats, or complex values. Strings are ordered sequences of characters that can use single, double, or triple quotes. Lists are mutable sequences that use brackets, tuples are immutable sequences that use parentheses, and sets are unordered collections defined with curly braces. Dictionaries store key-value pairs within curly braces. Python has arithmetic, relational, logical, bitwise, assignment, identity, and membership operators, which follow precedence and associativity rules.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Write A Detailed Note About Datatypes and Operators in Python

Python has six main data types: numbers, strings, lists, tuples, sets, and dictionaries. Numbers can be integers, floats, or complex values. Strings are ordered sequences of characters that can use single, double, or triple quotes. Lists are mutable sequences that use brackets, tuples are immutable sequences that use parentheses, and sets are unordered collections defined with curly braces. Dictionaries store key-value pairs within curly braces. Python has arithmetic, relational, logical, bitwise, assignment, identity, and membership operators, which follow precedence and associativity rules.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a detailed note about Datatypes and

Operators in Python
Python Data Types
A Data Type describes the characteristic of a variable.

Python has six standard Data Types:


#1) Numbers
In Numbers, there are mainly 3 types which include Integer, Float, and Complex.

These 3 are defined as a class in python. In order to find to which class the variable
belongs to you can use type () function.

#2) String
A string is an ordered sequence of characters.

We can use single quotes or double quotes to represent strings. Multi-line strings
can be represented using triple quotes, ”’ or “””.

Strings are immutable which means once we declare a string we can’t update the
already declared string.

#3) List
A list can contain a series of values.

List variables are declared by using brackets [ ]. A list is mutable, which means we
can modify the list.

#4) Tuple
A tuple is a sequence of Python objects separated by commas.

Tuples are immutable, which means tuples once created cannot be modified. Tuples
are defined using parentheses ().

#5) Set
A set is an unordered collection of items. Set is defined by values separated by a
comma inside braces { }.

#6) Dictionary
Dictionaries are the most flexible built-in data type in python.
Dictionaries items are stored and fetched by using the key. Dictionaries are used to
store a huge amount of data. To retrieve the value we must know the key. In Python,
dictionaries are defined within braces {}.

We use the key to retrieve the respective value. But not the other way around.

Python Operators
Arithmetic operators: Arithmetic operators are used to perform
mathematical operations like addition, subtraction, multiplication and
division.

Relational Operators: Relational operators compares the values. It


either returns True or False according to the condition.

Logical operators: Logical operators perform Logical AND, Logical


OR and Logical NOT operations.

Bitwise operators: Bitwise operators acts on bits and performs bit by


bit operation.

Assignment operators: Assignment operators are used to assign


values to the variables.

Special operators: There are some special type of operators like-


 Identity operators-
is and is not are the identity operators both are used to check if
two values are located on the same part of the memory. Two
variables that are equal does not imply that they are identical
 Membership operators-
in and not in are the membership operators; used to test
whether a value or variable is in a sequence.

Precedence and Associativity :Operator precedence and


associativity as these determine the priorities of the operator.
 Operator Precedence: This is used in an expression with more
than one operator with different precedence to determine which
operation to perform first.
 Operator Associativity: If an expression contains two or more
operators with the same precedence then Operator Associativity
is used to determine. It can either be Left to Right or from Right
to Left.

You might also like