KEMBAR78
Expressions in Python 240812 220052 | PDF | Arithmetic | Computer Programming
0% found this document useful (0 votes)
21 views15 pages

Expressions in Python 240812 220052

The document outlines various types of expressions in Python, including constant, arithmetic, relational, logical, and bitwise expressions, along with their respective operators and precedence. It also describes Python's built-in data types, such as numeric, sequence, boolean, set, and dictionary, detailing their characteristics and usage. The document emphasizes the importance of operator precedence in evaluating expressions and the classification of data types in Python programming.

Uploaded by

vigneshbala302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views15 pages

Expressions in Python 240812 220052

The document outlines various types of expressions in Python, including constant, arithmetic, relational, logical, and bitwise expressions, along with their respective operators and precedence. It also describes Python's built-in data types, such as numeric, sequence, boolean, set, and dictionary, detailing their characteristics and usage. The document emphasizes the importance of operator precedence in evaluating expressions and the classification of data types in Python programming.

Uploaded by

vigneshbala302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

EXPRESSIONS IN PYTHON:

An expression is a combination of operators and operands that is interpreted to


produce some other value. In any programming language, an expression is evaluated
as per the precedence of its operators. So that if there is more than one operator in
an expression, their precedence decides which operation will be performed first.
1. Constant Expressions: These are the expressions that have constant values only.
Example:

2. Arithmetic Expressions: An arithmetic expression is a combination of numeric


values, operators, and sometimes parenthesis. The result of this type of expression
is also a numeric value. The operators used in these expressions are arithmetic
operators like addition, subtraction, etc. Here are some arithmetic operators in
Python:

Operators Syntax Functioning

+ x+y Addition

– x–y Subtraction

* x*y Multiplication
/ x/y Division

// x // y Quotient

% x%y Remainder

** x ** y Exponentiation

Example:

3. Integral Expressions: These are the kind of expressions that produce only integer
results after all computations and type conversions.
Example:
4. Floating Expressions: These are the kind of expressions which produce floating
point numbers as result after all computations and type conversions.
Example:

5. Relational Expressions: In these types of expressions, arithmetic expressions are


written on both sides of relational operator (> , < , >= , <=). Those arithmetic
expressions are evaluated first, and then compared as per relational operator and
produce a boolean output in the end. These expressions are also called Boolean
expressions.
Example:
6. Logical Expressions: These are kinds of expressions that result in
either True or False. It basically specifies one or more conditions.

Operator Syntax Functioning

It returns true if both P and Q are true otherwise returns


and P and Q
false

or P or Q It returns true if at least one of P and Q is true

not not P It returns true if condition P is false

Example:
7. Bitwise Expressions: These are the kind of expressions in which computations
are performed at bit level.
Example:
8. Combinational Expressions: We can also use different types of expressions in a
single expression, and that will be termed as combinational expressions.
Example:

Multiple operators in expression (Operator Precedence)


Operator Precedence simply defines the priority of operators that which operator is
to be executed first. Here , it is shown the operator precedence in Python, where the
operator higher in the list has more precedence or priority:

Precedence Name Operator

1 Parenthesis ()[]{}

2 Exponentiation **

3 Unary plus or minus, complement -a , +a , ~a

4 Multiply, Divide, Modulo / * // %

5 Addition & Subtraction + –


Precedence Name Operator

6 Shift Operators >> <<

7 Bitwise AND &

8 Bitwise XOR ^

9 Bitwise OR |

10 Comparison Operators >= <= > <

11 Equality Operators == !=

12 Assignment Operators = += -= /= *=

13 Identity and membership operators is, is not, in, not in

14 Logical Operators and, or, not

DATATYPES IN PYTHON:
Python Data types are the classification or categorization of data items. It represents
the kind of value that tells what operations can be performed on a particular data.
Since everything is an object in Python programming, Python data types are classes
and variables are instances (objects) of these classes. The following are the standard
or built-in data types in Python:
• Numeric
• Sequence Type
• Boolean
• Set
• Dictionary

1. Numeric Data Types in Python


The numeric data type in Python represents the data that has a numeric
value. A numeric value can be an integer, a floating number, or even a
complex number. These values are defined as Python int, Python float,
and Python complex classes in Python.
• Integers – This value is represented by int class. It contains positive
or negative whole numbers (without fractions or decimals). In
Python, there is no limit to how long an integer value can be.
• Float – This value is represented by the float class. It is a real number
with a floating-point representation. It is specified by a decimal
point. Optionally, the character e or E followed by a positive or
negative integer may be appended to specify scientific notation.
• Complex Numbers – A complex number is represented by a
complex class. It is specified as (real part) + (imaginary part)j. For
example – 2+3j
• type() function is used to determine the type of Python data type.
• Example: This code demonstrates how to determine the data type
of variables in Python using the type() function. It prints the data
types of three variables: a (integer), b (float), and c (complex). The
output shows the respective data type Python for each variable.

2. Sequence Data Types in Python


The sequence Data Type in Python is the ordered collection of similar or different
Python data types. Sequences allow storing of multiple values in an organized and
efficient fashion. There are several sequence data types of Python:
• Python String
• Python List
• Python Tuple
String Data Type
Strings in Python are arrays of bytes representing Unicode characters. A string is a
collection of one or more characters put in a single quote, double-quote, or triple-
quote. In Python, there is no character data type Python, a character is a string of
length one. It is represented by str class.
Creating String
Strings in Python can be created using single quotes, double quotes, or even triple
quotes.
List
Lists in Python are like arrays in C, but lists can contain data of different types. The
things put away in the rundown are isolated with a comma (,) and encased inside
square sections [].
To gain access to the list's data, we can use slice [:] operators. Like how they worked
with strings, the list is handled by the concatenation operator (+) and the repetition
operator (*).
Tuple
In many ways, a tuple is like a list. Tuples, like lists, also contain a collection of
items from various data types. A parenthetical space () separates the tuple's
components from one another.
Because we cannot alter the size or value of the items in a tuple, it is a read-only data
structure.
Dictionary
A dictionary is a key-value pair set arranged in any order. It stores a specific value
for each key, like an associative array or a hash table. Value is any Python object,
while the key can hold any primitive data type.
The comma (,) and the curly braces are used to separate the items in the dictionary.
Boolean
True and False are the two default values for the Boolean type. These qualities are
utilized to decide the given assertion valid or misleading. The class bool indicates
this. False can be represented by the 0 or the letter "F," while true can be represented
by any value that is not zero.
Example:

Set
The data type's unordered collection is Python Set. It is iterable, mutable(can change
after creation), and has remarkable components. The elements of a set have no set
order; It might return the element's altered sequence.
Either a sequence of elements is passed through the curly braces and separated by a
comma to create the set or the built-in function set() is used to create the set. It can
contain different kinds of values.
Example:

You might also like