The document discusses various operators in Python including arithmetic, comparison, bitwise, logical, and membership operators. It provides examples of using each operator and explains their functionality. The key types of operators covered are arithmetic (e.g. +, -, *, /), comparison (e.g. ==, !=, >, <), bitwise (e.g. &, |, ^), logical (e.g. and, or, not), and membership (e.g. in, not in) operators. It also discusses operator precedence and provides examples of expressions using different operators.
The document discusses various operators and statements in the Python programming language. It covers arithmetic, comparison, logical, assignment, membership, and bitwise operators. It also explains control flow statements like if-else, while, for, break, continue, and pass in Python. Key operators and statements are defined with examples to illustrate their usage.
This document discusses various operators and statements in the Python programming language. It covers arithmetic, comparison, logical, assignment, membership, and bitwise operators. It also explains control flow statements like if/elif/else, while loops, for loops, and the break, continue, and pass statements. Key points include:
- Python supports operators for arithmetic, comparison, assignment, logical/relational, conditional, and bitwise operations
- Control structures include if/elif/else conditional execution, while and for iterative loops, and break, continue, and pass statements to control loop behavior
- Loops like while and for allow iterating over sequences with optional else blocks to execute after normal termination
The document discusses various operators and statements in Python. It covers arithmetic, comparison, logical, assignment, membership, and bitwise operators. It also discusses control flow statements like if-else, while, for, break, continue, else and pass statements. The key points are:
- Python supports operators like +, -, *, /, % for arithmetic. ==, !=, >, < for comparison. and, or, not for logical operations.
- if-else and nested if-elif-else statements allow conditional execution of code blocks.
- while and for loops iterate over blocks until a condition is met or a sequence is exhausted.
- break and continue can terminate or skip iterations in loops.
The document discusses various operators and control flow statements in Python. It covers arithmetic, comparison, logical, assignment and membership operators. It also covers if-else conditional statements, while and for loops, and break, continue and pass statements used with loops. The key points are:
- Python supports operators like +, -, *, / etc. for arithmetic and ==, !=, >, < etc. for comparison.
- Control flow statements include if-else for conditional execution, while and for loops for repetition, and break/continue to control loop flow.
- The while loop repeats as long as the condition is true. for loops iterate over sequences like lists, tuples using a loop variable.
Operators in Python are special symbols or keywords that are used to perform operations on variables and values. Python supports various types of operators, each designed for specific purposes.
Python Programming | JNTUK | UNIT 1 | Lecture 5FabMinds
This document provides an overview of the topics covered in Unit 1 of a Python programming syllabus. It includes introductions to computer science topics, computer systems, installing Python, basic syntax, data types, variables, arithmetic operators, expressions, comments, and understanding error messages. Example code and explanations of operators like arithmetic, assignment, comparison, logical, membership, identity, and bitwise are also provided.
This document summarizes Python operators including arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. It provides examples of common operators like addition, subtraction, equality checking, and shows how operators like assignment, logical AND, and bitwise XOR work. Usage examples are given for arithmetic operations, comparisons, and basic programs.
Python tutorials for beginners | IQ Online TrainingRahul Tandale
Python training program walks you through basics of python language and gives you in-depth knowledge of function,collections,REs,Exception Handing,
Socket programming and OOP basics.The course also explains object-oriented as well as functional programming techniques,error handling,packaging system and network programming.The course curriculum is designed for developer,system administrators and QA engineers.
This program also covers many of python extensions(libraries)as well as best practices
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxJahnavi113937
This document provides an overview of data types, variables, operators and expressions in Python. It discusses the core data types in Python including numbers, strings, lists, tuples and dictionaries. It also covers the differences between mutable and immutable data types. The document explains various operators in Python like arithmetic, relational, logical and bitwise operators. It describes expressions, type casting, and how to take input in Python programs.
This document summarizes the different types of operators in Python. It discusses arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. For each type of operator, it provides examples to illustrate how they are used including the syntax. The key types of operators covered are arithmetic (+ - * /), comparison (== != > <), logical (and or not), and assignment (= += -= etc) operators. It aims to explain how each type of operator works and provides sample code to demonstrate their usage in Python programs.
Python interpreter and interactive mode, debugging; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence of operators, comments; Illustrative programs: exchange the values of two variables, circulate the values of n variables, distance between two points.
Python supports common data types like numbers, strings, booleans, lists, tuples, sets and dictionaries. Numbers can be integers, floating point numbers or complex numbers. Strings are sequences of characters that can be indexed and manipulated. Booleans represent true and false values. Lists are mutable sequences that can hold heterogeneous data types. Tuples are immutable sequences similar to lists. Sets hold unique elements without defined ordering. Dictionaries store mappings of unique keys to values.
Operators are symbols that represent actions or processes performed on operands. There are several types of operators including arithmetic, relational, logical, bitwise, assignment, identity, and membership operators. Arithmetic operators perform math operations, relational operators compare values, logical operators combine conditional statements, bitwise operators work with bits, assignment operators assign values, identity operators check object equality, and membership operators check if a value is contained within an object. Operators require operands as inputs to perform their defined actions and return results.
The document discusses various operators in Python including assignment, comparison, logical, identity, and membership operators. It provides examples of how each operator works and the output. Specifically, it explains that assignment operators are used to assign values to variables using shortcuts like +=, -=, etc. Comparison operators compare values and return True or False. Logical operators combine conditional statements using and, or, and not. Identity operators compare the memory location of objects using is and is not. Membership operators test if a value is present in a sequence using in and not in.
Operators are the foundation of any programming language. Thus the functionality of C/C++ programming language is incomplete without the use of operators. We can define operators as symbols that helps us to perform specific mathematical and logical computations on operands. In other words we can say that an operator operates the operands.
This document discusses different types of operators in Python programming. It defines operators as symbols that represent operations that can be performed on operands or values. The main types of operators covered are: arithmetic operators for mathematical operations, relational operators for comparisons, logical operators for Boolean logic, assignment operators for assigning values, and special operators like identity and membership. Examples are provided to demonstrate the usage of each operator type.
Operators in Python are special symbols or keywords that are used to perform operations on variables and values. Python supports various types of operators, each designed for specific purposes.
Python Programming | JNTUK | UNIT 1 | Lecture 5FabMinds
This document provides an overview of the topics covered in Unit 1 of a Python programming syllabus. It includes introductions to computer science topics, computer systems, installing Python, basic syntax, data types, variables, arithmetic operators, expressions, comments, and understanding error messages. Example code and explanations of operators like arithmetic, assignment, comparison, logical, membership, identity, and bitwise are also provided.
This document summarizes Python operators including arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. It provides examples of common operators like addition, subtraction, equality checking, and shows how operators like assignment, logical AND, and bitwise XOR work. Usage examples are given for arithmetic operations, comparisons, and basic programs.
Python tutorials for beginners | IQ Online TrainingRahul Tandale
Python training program walks you through basics of python language and gives you in-depth knowledge of function,collections,REs,Exception Handing,
Socket programming and OOP basics.The course also explains object-oriented as well as functional programming techniques,error handling,packaging system and network programming.The course curriculum is designed for developer,system administrators and QA engineers.
This program also covers many of python extensions(libraries)as well as best practices
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxJahnavi113937
This document provides an overview of data types, variables, operators and expressions in Python. It discusses the core data types in Python including numbers, strings, lists, tuples and dictionaries. It also covers the differences between mutable and immutable data types. The document explains various operators in Python like arithmetic, relational, logical and bitwise operators. It describes expressions, type casting, and how to take input in Python programs.
This document summarizes the different types of operators in Python. It discusses arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators. For each type of operator, it provides examples to illustrate how they are used including the syntax. The key types of operators covered are arithmetic (+ - * /), comparison (== != > <), logical (and or not), and assignment (= += -= etc) operators. It aims to explain how each type of operator works and provides sample code to demonstrate their usage in Python programs.
Python interpreter and interactive mode, debugging; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence of operators, comments; Illustrative programs: exchange the values of two variables, circulate the values of n variables, distance between two points.
Python supports common data types like numbers, strings, booleans, lists, tuples, sets and dictionaries. Numbers can be integers, floating point numbers or complex numbers. Strings are sequences of characters that can be indexed and manipulated. Booleans represent true and false values. Lists are mutable sequences that can hold heterogeneous data types. Tuples are immutable sequences similar to lists. Sets hold unique elements without defined ordering. Dictionaries store mappings of unique keys to values.
Operators are symbols that represent actions or processes performed on operands. There are several types of operators including arithmetic, relational, logical, bitwise, assignment, identity, and membership operators. Arithmetic operators perform math operations, relational operators compare values, logical operators combine conditional statements, bitwise operators work with bits, assignment operators assign values, identity operators check object equality, and membership operators check if a value is contained within an object. Operators require operands as inputs to perform their defined actions and return results.
The document discusses various operators in Python including assignment, comparison, logical, identity, and membership operators. It provides examples of how each operator works and the output. Specifically, it explains that assignment operators are used to assign values to variables using shortcuts like +=, -=, etc. Comparison operators compare values and return True or False. Logical operators combine conditional statements using and, or, and not. Identity operators compare the memory location of objects using is and is not. Membership operators test if a value is present in a sequence using in and not in.
Operators are the foundation of any programming language. Thus the functionality of C/C++ programming language is incomplete without the use of operators. We can define operators as symbols that helps us to perform specific mathematical and logical computations on operands. In other words we can say that an operator operates the operands.
This document discusses different types of operators in Python programming. It defines operators as symbols that represent operations that can be performed on operands or values. The main types of operators covered are: arithmetic operators for mathematical operations, relational operators for comparisons, logical operators for Boolean logic, assignment operators for assigning values, and special operators like identity and membership. Examples are provided to demonstrate the usage of each operator type.
Spring data jpa are used to develop spring applicationsmichaelaaron25322
Spring Data JPA helps overcome limitations of JDBC API and raw JPA by automatically generating data access code. It reduces boilerplate code through repository interfaces that expose CRUD methods. The programmer defines database access methods in repository interfaces rather than implementing them, avoiding inconsistency. A Spring Data JPA project contains pom.xml, Spring Boot starters, application.properties, and main class annotated with @SpringBootApplication to run the application.
This document provides an introduction to Python programming. It discusses the history and origins of Python, its key features and applications. Some of the main points covered include:
- Python was created in the late 1980s by Guido van Rossum and takes influence from other languages like ABC, Modula-3, C, C++ and Unix shell scripts.
- Python is an interpreted, object-oriented scripting language that is designed to be highly readable. It has applications in systems programming, GUIs, web development, data analysis, scientific computing and more.
- The document outlines Python's technical strengths like being free, portable, powerful, easy to use and learn. It also covers basics like variables,
The document discusses TypeScript concepts including:
- TypeScript adds static typing to JavaScript for type safety and catches errors.
- It is transpiled to JavaScript using a compiler for browser compatibility.
- The document covers TypeScript basics like functions, parameters, return types, interfaces, classes, modules and generics.
- Functions, parameters and return types are typed for type safety. Interfaces define structures without implementation.
- Classes create object templates with fields and methods. Namespaces and modules organize code. Generics enable code reuse.
Unit-II AES Algorithm which is used machine learningmichaelaaron25322
The document discusses the Advanced Encryption Standard (AES) algorithm. AES is a symmetric block cipher that uses 128-bit blocks and 128, 192, or 256-bit keys. It operates on a 4x4 column-row matrix through a series of transformations including byte substitution, shifting rows, mixing columns, and adding a round key. The key is expanded through successive XOR operations to derive round keys for each round. At the end of the class, students will be able to implement AES to securely transfer data over a network.
UNIT2_NaiveBayes algorithms used in machine learningmichaelaaron25322
This document provides an overview of Naive Bayes classifiers and Support Vector Machines (SVMs). It discusses the key concepts behind Naive Bayes, including Bayes' theorem and the assumption of independence among predictors. It also explains how Naive Bayes classifiers work and are implemented in scikit-learn. Specifically, it covers Bernoulli, Multinomial, and Gaussian Naive Bayes models. The document then discusses SVMs, focusing on linear and kernel-based classification as well as support vector regression. Examples of applications of Naive Bayes and pros/cons of the approach are also summarized.
Spring Data JPA provides features for pagination, sorting, and querying data from a database. It supports defining queries declaratively through method names, named queries annotated with @NamedQuery, and custom queries annotated with @Query. Transactions in Spring manage a sequence of database operations atomically through programmatic or declarative transaction management using annotations or configuration. Custom repositories may also be implemented to define additional queries beyond standard Spring Data JPA features.
Computer organization algorithms like addition and subtraction and multiplica...michaelaaron25322
The document discusses hardware implementations for addition, subtraction, multiplication and division in computer systems. It describes:
1) The hardware needed for addition and subtraction, including parallel adders, comparators and subtractors.
2) Algorithms for signed and two's complement addition and subtraction using adders, complementers and registers.
3) Hardware designs for multiplication like array multipliers and Booth's algorithm.
4) Division algorithms using shift-and-subtract methods and the hardware required including registers for the divisor, dividend and quotient.
Angular is an open-source JavaScript framework for building mobile and desktop web applications. It uses TypeScript for development and focuses on building single page applications. The key aspects of Angular include components, modules, templates and data binding.
To set up an Angular application, developers must install Node.js, Angular CLI and configure the development environment. The Angular CLI is used to generate components, run tests and deploy applications. Components and modules are fundamental building blocks - components define views and logic, while modules organize an application's components. Data binding in templates connects application data and DOM elements.
The Karnaugh map is a method to simplify Boolean algebra expressions by grouping adjacent 1s in a two-dimensional grid ordered in Gray code.
Groups of 1s must have an area that is a power of 2, cannot include any 0s, and should be as large as possible. Each 1 must be in at least one group.
Simplified expressions are obtained by examining which variables stay the same within each group and including or excluding them from the expression. Don't cares can be included to make groups larger.
Boolean algebra can be used to simplify digital circuit expressions. A Boolean function can be represented as either a logical expression using AND, OR, and NOT operators or as a truth table. There are standard methods to convert between these representations, such as using sums of minterms or products of maxterms. Boolean algebra postulates and theorems allow logical expressions to be simplified in ways that result in equivalent but simpler circuits.
The document provides an introduction to HTML by describing its key components and purposes. It explains that HTML is the standard markup language used to define the structure of web pages. HTML uses elements to describe headings, paragraphs, and other content. Elements tell browsers how to display text and other media. The document also gives a simple example of an HTML file structure.
May 2025: Top 10 Read Articles Advanced Information Technologyijait
International journal of advanced Information technology (IJAIT) is a bi monthly open access peer-reviewed journal, will act as a major forum for the presentation of innovative ideas, approaches, developments, and research projects in the area advanced information technology applications and services. It will also serve to facilitate the exchange of information between researchers and industry professionals to discuss the latest issues and advancement in the area of advanced IT. Core areas of advanced IT and multi-disciplinary and its applications will be covered during the conferences.
This research presents a machine learning (ML) based model to estimate the axial strength of corroded RC columns reinforced with fiber-reinforced polymer (FRP) composites. Estimating the axial strength of corroded columns is complex due to the intricate interplay between corrosion and FRP reinforcement. To address this, a dataset of 102 samples from various literature sources was compiled. Subsequently, this dataset was employed to create and train the ML models. The parameters influencing axial strength included the geometry of the column, properties of the FRP material, degree of corrosion, and properties of the concrete. Considering the scarcity of reliable design guidelines for estimating the axial strength of RC columns considering corrosion effects, artificial neural network (ANN), Gaussian process regression (GPR), and support vector machine (SVM) techniques were employed. These techniques were used to predict the axial strength of corroded RC columns reinforced with FRP. When comparing the results of the proposed ML models with existing design guidelines, the ANN model demonstrated higher predictive accuracy. The ANN model achieved an R-value of 98.08% and an RMSE value of 132.69 kN which is the lowest among all other models. This model fills the existing gap in knowledge and provides a precise means of assessment. This model can be used in the scientific community by researchers and practitioners to predict the axial strength of FRP-strengthened corroded columns. In addition, the GPR and SVM models obtained an accuracy of 98.26% and 97.99%, respectively.
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyYannis
The doctoral thesis trajectory has been often characterized as a “long and windy road” or a journey to “Ithaka”, suggesting the promises and challenges of this journey of initiation to research. The doctoral candidates need to complete such journey (i) preserving and even enhancing their wellbeing, (ii) overcoming the many challenges through resilience, while keeping (iii) high standards of ethics and (iv) scientific rigor. This talk will provide a personal account of lessons learnt and recommendations from a senior researcher over his 30+ years of doctoral supervision and care for doctoral students. Specific attention will be paid on the special features of the (i) interdisciplinary doctoral research that involves Information and Communications Technologies (ICT) and other scientific traditions, and (ii) the challenges faced in the complex technological and research landscape dominated by Artificial Intelligence.
This presentation highlights project development using software development life cycle (SDLC) with a major focus on incorporating research in the design phase to develop innovative solution. Some case-studies are also highlighted which makes the reader to understand the different phases with practical examples.
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...ijccmsjournal
In order to evaluate side-effect of power limitation due to the Fast Automated Demand Response
(FastADR) for building air-conditioning facilities, a prediction model on short time change of average
room temperature has been developed. A room temperature indexis defined as a weighted average of the
entire building for room temperature deviations from the setpoints. The index is assumed to be used to
divide total FastADRrequest to distribute power limitation commands to each building.In order to predict
five-minute-change of the index, our combined mathematical model of an auto regression (AR) and a
neural network (NN) is proposed.In the experimental results, the combined model showedthe root mean
square error (RMSE) of 0.23 degrees, in comparison with 0.37 and 0.26 for conventional single NN and AR
models, respectively. This result is satisfactory prediction for required comfort of approximately 1 degree
Celsius allowance.
Electrical and Electronics Engineering: An International Journal (ELELIJ)elelijjournal653
Call For Papers...!!!
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Web page link: https://wireilla.com/engg/eeeij/index.html
Submission Deadline: June 08, 2025
Submission link: [email protected]
Contact Us: [email protected]
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...ijscai
International Journal on Soft Computing, Artificial Intelligence and Applications (IJSCAI) is an open access peer-reviewed journal that provides an excellent international forum for sharing knowledge and results in theory, methodology and applications of Artificial Intelligence, Soft Computing. The Journal looks for significant contributions to all major fields of the Artificial Intelligence, Soft Computing in theoretical and practical aspects. The aim of the Journal is to provide a platform to the researchers and practitioners from both academia as well as industry to meet and share cutting-edge development in the field.
Call For Papers - International Journal on Natural Language Computing (IJNLC)kevig
Natural Language Processing is a programmed approach to analyze text that is based on both a
set of theories and a set of technologies. This forum aims to bring together researchers who have
designed and build software that will analyze, understand, and generate languages that humans use
naturally to address computers.
1. Python Programming
UNIT II
• Types, Operators and Expressions: Types -
Integers, Strings, Booleans; Operators- Arithmetic
Operators, Comparison (Relational) Operators,
Assignment Operators, Logical Operators, Bitwise
Operators, Membership Operators, Identity
Operators
• Expressions and order of evaluations Control
Flow- if, if-elif-else, for, while, break, continue,
pass
2. Standard Data Types
The data stored in memory can be of many types. For example, a person's age is
stored as a numeric value and his or her address is stored as alphanumeric
characters. Python has various standard data types that are used to define the
operations possible on them and the storage method for each of them.
Python supports following standard data types:
• Numbers
• String
• Boolean
4. Python Strings
Strings in Python are identified as a contiguous set of characters represented in the
quotation marks. Python allows for either pairs of single or double quotes. Subsets
of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0
in the beginning of the string and working their way from -1 at the end.
The plus (+) sign is the string concatenation operator and the asterisk (*) is the
repetition operator.
For example:
Program:
str ="WELCOME"
print str # Prints complete string
print str[0] # Prints first character of the string
print str[2:5] # Prints characters starting from 3rd to 4th print str[2:] # Prints string
starting from 3rd character print str * 2 # Prints string two times
print str + "CSE" # Prints concatenated string
5. Exercise
• In this challenge, the user enters a string and a substring. You have
to print the number of times that the substring occurs in the given
string. String traversal will take place from left to right, not from
right to left.
• NOTE: String letters are case-sensitive.
• Input Format
• The first line of input contains the original string. The next line
contains the substring.
• Constraints
Each character in the string is an ascii character.
• Output Format
• Output the integer number indicating the total number of
occurrences of the substring in the original string.
• Sample Input
• ABCDCDC CDC Sample Output
• 2
6. Booleans are identified by True or False.
Example:
Program:
a = True
b = False
print(a)
print(b)
Output:
True False
Python Boolean
7. Python - Basic Operators
Python language supports following type of operators.
• Arithmetic Operators
• Relational(Comparision) Operators
• Logical Operators
• Assignment Operators
• Bitwise operators
• Membership operators
• Identity operstors
8. Python Arithmetic Operators:
Operator Description Example
+ Addition - Adds values on either side of the
operator
a + b will give 30
- Subtraction - Subtracts right hand operand
from left hand operand
a - b will give -10
* Multiplication - Multiplies values on either
side of the operator
a * b will give 200
/ Division - Divides left hand operand by
right hand operand
b / a will give 2
% Modulus - Divides left hand operand by
right hand operand and returns remainder
b % a will give 0
** Exponent - Performs exponential (power)
calculation on operators
a**b will give 10 to
the power 20
// Floor Division - The division of operands
where the result is the quotient in which
the digits after the decimal point are
removed.
9//2 is equal to 4 and
9.0//2.0 is equal to 4.0
9. Python Comparison Operators:
Operato
r
Description Example
== Checks if the value of two operands are equal or not, if
yes then condition becomes true.
(a == b) is not true.
!= Checks if the value of two operands are equal or not, if
values are not equal then condition becomes true.
(a != b) is true.
<> Checks if the value of two operands are equal or not, if
values are not equal then condition becomes true.
(a <> b) is true. This is
similar to != operator.
> Checks if the value of left operand is greater than the
value of right operand, if yes then condition becomes
true.
(a > b) is not true.
< Checks if the value of left operand is less than the
value of right operand, if yes then condition becomes
true.
(a < b) is true.
>= Checks if the value of left operand is greater than or
equal to the value of right operand, if yes then
condition becomes true.
(a >= b) is not true.
<= Checks if the value of left operand is less than or equal
to the value of right operand, if yes then condition
becomes true.
(a <= b) is true.
10. Python Assignment Operators:
Operator Description Example
= Simple assignment operator, Assigns values from right
side operands to left side operand
c = a + b will
assigne value of a +
b into c
+= Add AND assignment operator, It adds right operand to
the left operand and assign the result to left operand
c += a is equivalent
to c = c + a
-= Subtract AND assignment operator, It subtracts right
operand from the left operand and assign the result to left
operand
c -= a is equivalent
to c = c - a
*= Multiply AND assignment operator, It multiplies right
operand with the left operand and assign the result to left
operand
c *= a is equivalent
to c = c * a
/= Divide AND assignment operator, It divides left operand
with the right operand and assign the result to left
operand
c /= a is equivalent
to c = c / a
%= Modulus AND assignment operator, It takes modulus
using two operands and assign the result to left operand
c %= a is equivalent
to c = c % a
**= Exponent AND assignment operator, Performs exponential
(power) calculation on operators and assign value to the
left operand
c **= a is
equivalent to c = c
** a
//= Floor Division and assigns a value, Performs floor division
on operators and assign value to the left operand
c //= a is equivalent
to c = c // a
11. Python Bitwise Operators:
Operat
or
Description Example
& Binary AND Operator copies a bit to the
result if it exists in both operands.
(a & b) will give 12
which is 0000 1100
| Binary OR Operator copies a bit if it exists
in either operand.
(a | b) will give 61
which is 0011 1101
^ Binary XOR Operator copies the bit if it is
set in one operand but not both.
(a ^ b) will give 49
which is 0011 0001
~ Binary Ones Complement Operator is unary
and has the effect of 'flipping' bits.
(~a ) will give -60
which is 1100 0011
<< Binary Left Shift Operator. The left
operands value is moved left by the
number of bits specified by the right
operand.
a << 2 will give 240
which is 1111 0000
>> Binary Right Shift Operator. The left
operands value is moved right by the
number of bits specified by the right
operand.
a >> 2 will give 15
which is 0000 1111
12. Python Logical Operators:
Operat
or
Description Example
and Called Logical AND operator. If both the
operands are true then then condition
becomes true.
(a and b)
or Called Logical OR Operator. If any of the two
operands are non zero then then condition
becomes true.
(a or b)
not Called Logical NOT Operator. Use to
reverses the logical state of its operand. If a
condition is true then Logical NOT operator
will make false.
not(a and b)
13. Python Membership Operators:
In addition to the operators discussed previously, Python has membership
operators, which test for membership in a sequence, such as strings, lists,
or tuples.
Operator Description Example
in Evaluates to true if it finds a variable in the
specified sequence and false otherwise.
x in y, here in results in a
1 if x is a member of
sequence y.
not in Evaluates to true if it does not finds a
variable in the specified sequence and false
otherwise.
x not in y, here not in
results in a 1 if x is a
member of sequence y.
14. Python Membership Operators:
In addition to the operators discussed previously, Python has membership
operators, which test for membership in a sequence, such as strings, lists,
or tuples.
Operator Description Example
is Evaluates to true if the variables on either
side of the operator point to the same
object and false otherwise.
x is y, here is results in 1 if
id(x) equals id(y).
is not Evaluates to false if the variables on either
side of the operator point to the same
object and true otherwise.
x is not y, here is not
results in 1 if id(x) is not
equal to id(y).
15. Python Operators Precedence
Operator Description
** Exponentiation (raise to the power)
~ + - Ccomplement, unary plus and minus (method names for
the last two are +@ and -@)
* / % // Multiply, divide, modulo and floor division
+ - Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'
^ | Bitwise exclusive `OR' and regular `OR'
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= +=
*= **=
Assignment operators
is is not Identity operators
in not in Membership operators
not or and Logical operators
16. Expression
• An expression is a combination of variables
constants and operators written according to
the syntax of Python language. In Python
every expression evaluates to a value i.e.,
every expression results in some value of a
certain type that can be assigned to a variable.
Some examples of Python expressions are
shown in the table given below.
Algebraic Expression Python Expression
a x b – c a * b – c
(m + n) (x + y) (m + n) * (x + y)
(ab / c) a * b / c
3x2 +2x + 1 3*x*x+2*x+1
(x / y) + c x / y + c
17. Evaluation of Expressions
• Expressions are evaluated using an assignment statement of the form
• Variable = expression
• Variable is any valid C variable name. When the statement is encountered, the
expression is evaluated first and then replaces the previous value of the variable
on the left hand side. All variables used in the expression must be assigned values
before evaluation is attempted.
• Example:
• a=10 b=22 c=34
• x=a*b+c
• y=a-b*c
• z=a+b+c*c-a
• print "x=",x
• print "y=",y
• print "z=",z
• Output:
• x= 254
• y= -738
• z= 1178
18. Control Flow statements
(Decision making statements)
• Decision making is anticipation of
conditions occurring while execution of
the program and specifying actions
taken according to the conditions.
• Decision structures evaluate multiple
expressions which produce TRUE or
FALSE as outcome. You need to
determine which action to take and
which statements to execute if outcome
is TRUE or FALSE otherwise.
19. Control Flow statements
(Decision making statements)
• Python programming language
provides following types of
decision making statements
I. Simple if
II. If-else
III. If-elif
20. Python Simple If
if statement consists of a boolean expression followed by
one or more statements.
Syntax:
If(condition):
statement1
……………..
statement n
Example:
x=10
if(x==10):
print(' x is 10')
print(”simple if”)
if (expression):
statement(s)
24. The Nested if...elif...else Construct
Example:
var = 100
if var < 200:
print "Expression value is less than 200"
if var == 150:
print "Which is 150"
elif var == 100:
print "Which is 100"
elif var == 50:
print "Which is 50"
elif var < 50:
print "Expression value is less than 50"
else:
print "Could not find true expression"
print "Good bye!"
25. Single Statement Suites:
If the suite of an if clause consists only of a single line, it may go on the same
line as the header statement:
if ( expression == 1 ) : print "Value of expression is 1"
27. Python - Loop Statements
Loop Type Description
while loop Repeats a statement or group of statements while a given
condition is TRUE. It tests the condition before executing
the loop body.
for loop Executes a sequence of statements multiple times and
abbreviates the code that manages the loop variable.
nested
loops
You can use one or more loop inside any another while, for
loop.
28. 5. Python - while Loop Statements
• The while loop continues until the expression becomes false. The expression
has to be a logical expression and must return either a true or a false value
The syntax of the while loop is:
while expression:
statement(s)
Example:
count = 0
while (count < 9):
print (count,end=‘ ‘)
count = count + 1
print "Good bye!"
Output: 0 1 2 3 4 5 6 7 8
29. Infinite Loops
• You must use caution when using while loops because of the possibility
that this condition never resolves to a false value. This results in a loop
that never ends. Such a loop is called an infinite loop.
• An infinite loop might be useful in client/server programming where the
server needs to run continuously so that client programs can
communicate with it as and when required.
Following loop will continue
till you enter CTRL+C :
while(1):
print(“while loop”)
(Or)
while(True):
print(“while loop”)
30. Single Statement Suites:
• Similar to the if statement syntax, if your while clause consists only of a
single statement, it may be placed on the same line as the while header.
• Here is the syntax of a one-line while clause:
while expression : statement
We can also write multiple statements with semicolon
while expression : statement1;statement2;….stmtn
31. range
“range” creates a list of numbers in a specified range
range([start,] stop[, step]) -> list of integers
When step is given, it specifies the increment (or
decrement).
*range(5) means [0, 1, 2, 3, 4]
*range(5, 10) means[5, 6, 7, 8, 9]
* range(0, 10, 2) means[0, 2, 4, 6, 8]
33. for loop
Example1: (prints upto n-1)
n=5
for i in range(n):
print(i)
Example2:
for i in range(1,4):
print(i)
Example3:
for i in range(1,10,2):
print(i)
Example 4:
for i in range(50,10,-3):
print(i)
Syntax:
for i in range(start,end,step)
34. 6. Python - for Loop Statements
• The for loop in Python has the ability to iterate over the items of any
sequence, such as a list or a string.
• The syntax of the loop look is:
for iterating_var in sequence:
statements(s)
Example:
for letter in 'Python': # First Example
print ('Current Letter :', letter)
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # Second Example
print 'Current fruit :', fruit
print "Good bye!"
35. Iterating by Sequence Index:
• An alternative way of iterating through each item is by index offset into
the sequence itself:
• Example:
fruits = ['banana', 'apple', 'mango']
for index in range(len(fruits)):
print 'Current fruit :', fruits[index]
print "Good bye!"
37. 7. Python break,continue and pass Statements
The break Statement:
• The break statement in Python terminates the current loop and resumes
execution at the next statement, just like the traditional break found in C.
Example 2:
for i in range(1,6)':
if (i == 3):
break
print (i)
Output:1 2
Example 1:
for letter in 'Python':
if letter == 'h':
break
print (letter)
Output: pyt
38. • The continue statement in Python returns the control to the beginning of
the for/while loop. The continue statement rejects all the remaining
statements in the current iteration of the loop and moves the control
back to the top of the loop.
Example 2:
for i in range(1,6)':
if (i == 3):
continue
print (i)
Output:1 2 4 5
Example 1:
for letter in 'Python':
if letter == 'h':
continue
print (letter)
Output: pyton
Continue Statement:
39. The pass Statement:
• The pass statement in Python is used when a statement is required
syntactically but you do not want any command or code to execute.
• The pass statement is a null operation; nothing happens when it
executes. The pass is also useful in places where your code will eventually
go, but has not been written yet (e.g., in stubs for example):
Example 2:
for i in range(1,6)':
if (i == 3):
pass
print (i)
Output:1 2 3 4 5
Example 1:
for letter in 'Python':
if letter == 'h':
pass
print (letter)
Output: python
40. break,continue,pass
n=10
for i in range(n):
print(i,end=' ')
if(i==5):
break
n=10
for i in range(n):
if(i==5):
continue
print(i,end=' ')
n=10
for i in range(n):
if(i==5):
pass
print(i,end=' ')