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.
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.
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.
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 perform logical and mathematical calculations on operands in Python. This document discusses several types of operators in Python including arithmetic, relational, identity, logical, bitwise, and membership operators. Arithmetic operators are used for mathematical calculations like addition and multiplication. Relational operators compare operands, logical operators are used for logical conditions, and bitwise operators perform bit operations on binary representations of numbers.
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.
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 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
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.
Strings in python are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
ExampleGet your own Python Server
print("Hello")
print('Hello')
Quotes Inside Quotes
You can use quotes inside a string, as long as they don't match the quotes surrounding the string:
Example
print("It's alright")
print("He is called 'Johnny'")
print('He is called "Johnny"')
Assign String to a Variable
Assigning a string to a variable is done with the variable name followed by an equal sign and the string:
Example
a = "Hello"
print(a)
Multiline Strings
You can assign a multiline string to a variable by using three quotes:
Example
You can use three double quotes:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Or three single quotes:
Example
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
print(a)
Note: in the result, the line breaks are inserted at the same position as in the code.
ADVERTISEMENT
Strings are Arrays
Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters.
However, Python does not have a character data type, a single character is simply a string with a length of 1.
Square brackets can be used to access elements of the string.
Example
Get the character at position 1 (remember that the first character has the position 0):
a = "Hello, World!"
print(a[1])
Looping Through a String
Since strings are arrays, we can loop through the characters in a string, with a for loop.
Example
Loop through the letters in the word "banana":
for x in "banana":
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 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.
The document provides information about Python programming language:
- Python was created in the late 1980s and became widely popular in the early 2000s.
- It is a high-level, general-purpose, interpreted programming language that can be used for web, desktop, game development, data science, and more.
- Some key features of Python include dynamic typing, automatic memory management, and being multi-paradigm supporting object-oriented, imperative, functional programming styles.
Operators in Python include arithmetic, relational, logical, bitwise and assignment operators. Arithmetic operators perform mathematical operations like addition and multiplication. Relational operators compare values and return True or False. Logical operators combine conditional statements. Bitwise operators work on operands as binary digits and assignment operators assign values to variables. Special operators like identity and membership are also used. Operator precedence defines the order calculations are performed.
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.
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.
Python is a high-level general-purpose programming language created by Guido van Rossum in 1991. It is an interpreted language with simple syntax and readability. Python has many advantages like being easy to learn and use, having simple syntax, and allowing developers to write less code to do more. It is versatile and flexible, and can be used for tasks like machine learning, web development, desktop applications, and more. Popular applications built with Python include Instagram, YouTube, and Pinterest.
Operators perform logical and mathematical calculations on operands in Python. This document discusses several types of operators in Python including arithmetic, relational, identity, logical, bitwise, and membership operators. Arithmetic operators are used for mathematical calculations like addition and multiplication. Relational operators compare operands, logical operators are used for logical conditions, and bitwise operators perform bit operations on binary representations of numbers.
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.
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 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
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.
Strings in python are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
ExampleGet your own Python Server
print("Hello")
print('Hello')
Quotes Inside Quotes
You can use quotes inside a string, as long as they don't match the quotes surrounding the string:
Example
print("It's alright")
print("He is called 'Johnny'")
print('He is called "Johnny"')
Assign String to a Variable
Assigning a string to a variable is done with the variable name followed by an equal sign and the string:
Example
a = "Hello"
print(a)
Multiline Strings
You can assign a multiline string to a variable by using three quotes:
Example
You can use three double quotes:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Or three single quotes:
Example
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
print(a)
Note: in the result, the line breaks are inserted at the same position as in the code.
ADVERTISEMENT
Strings are Arrays
Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters.
However, Python does not have a character data type, a single character is simply a string with a length of 1.
Square brackets can be used to access elements of the string.
Example
Get the character at position 1 (remember that the first character has the position 0):
a = "Hello, World!"
print(a[1])
Looping Through a String
Since strings are arrays, we can loop through the characters in a string, with a for loop.
Example
Loop through the letters in the word "banana":
for x in "banana":
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 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.
The document provides information about Python programming language:
- Python was created in the late 1980s and became widely popular in the early 2000s.
- It is a high-level, general-purpose, interpreted programming language that can be used for web, desktop, game development, data science, and more.
- Some key features of Python include dynamic typing, automatic memory management, and being multi-paradigm supporting object-oriented, imperative, functional programming styles.
Operators in Python include arithmetic, relational, logical, bitwise and assignment operators. Arithmetic operators perform mathematical operations like addition and multiplication. Relational operators compare values and return True or False. Logical operators combine conditional statements. Bitwise operators work on operands as binary digits and assignment operators assign values to variables. Special operators like identity and membership are also used. Operator precedence defines the order calculations are performed.
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.
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.
Python is a high-level general-purpose programming language created by Guido van Rossum in 1991. It is an interpreted language with simple syntax and readability. Python has many advantages like being easy to learn and use, having simple syntax, and allowing developers to write less code to do more. It is versatile and flexible, and can be used for tasks like machine learning, web development, desktop applications, and more. Popular applications built with Python include Instagram, YouTube, and Pinterest.
"Orthoptera: Grasshoppers, Crickets, and Katydids pptxArshad Shaikh
Orthoptera is an order of insects that includes grasshoppers, crickets, and katydids. Characterized by their powerful hind legs, Orthoptera are known for their impressive jumping ability. With diverse species, they inhabit various environments, playing important roles in ecosystems as herbivores and prey. Their sounds, often produced through stridulation, are distinctive features of many species.
Updated About Me. Used for former college assignments.
Make sure to catch our weekly updates. Updates are done Thursday to Fridays or its a holiday/event weekend.
Thanks again, Readers, Guest Students, and Loyalz/teams.
This profile is older. I started at the beginning of my HQ journey online. It was recommended by AI. AI was very selective but fits my ecourse style. I am media flexible depending on the course platform. More information below.
AI Overview:
“LDMMIA Reiki Yoga refers to a specific program of free online workshops focused on integrating Reiki energy healing techniques with yoga practices. These workshops are led by Leslie M. Moore, also known as LDMMIA, and are designed for all levels, from beginners to those seeking to review their practice. The sessions explore various themes like "Matrix," "Alice in Wonderland," and "Goddess," focusing on self-discovery, inner healing, and shifting personal realities.”
How to Setup Lunch in Odoo 18 - Odoo guidesCeline George
In Odoo 18, the Lunch application allows users a convenient way to order food and pay for their meal directly from the database. Lunch in Odoo 18 is a handy application designed to streamline and manage employee lunch orders within a company.
IDSP is a disease surveillance program in India that aims to strengthen/maintain decentralized laboratory-based IT enabled disease surveillance systems for epidemic prone diseases to monitor disease trends, and to detect and respond to outbreaks in the early phases swiftly.....
Students will research and orally present a Colombian company using a visual tool, in order to develop their communication skills and intercultural understanding through the exploration of identity, innovation, and local culture, in connection with the IB global themes.
♥☽✷♥
Make sure to catch our weekly updates. Updates are done Thursday to Fridays or its a holiday/event weekend.
Thanks again, Readers, Guest Students, and Loyalz/teams.
This profile is older. I started at the beginning of my HQ journey online. It was recommended by AI. AI was very selective but fits my ecourse style. I am media flexible depending on the course platform. More information below.
AI Overview:
“LDMMIA Reiki Yoga refers to a specific program of free online workshops focused on integrating Reiki energy healing techniques with yoga practices. These workshops are led by Leslie M. Moore, also known as LDMMIA, and are designed for all levels, from beginners to those seeking to review their practice. The sessions explore various themes like "Matrix," "Alice in Wonderland," and "Goddess," focusing on self-discovery, inner healing, and shifting personal realities.”
♥☽✷♥
“So Life Happens-Right? We travel on. Discovering, Exploring, and Learning...”
These Reiki Sessions are timeless and about Energy Healing / Energy Balancing.
A Shorter Summary below.
A 7th FREE WORKSHOP
REiki - Yoga
“Life Happens”
Intro Reflections
Thank you for attending our workshops. If you are new, do welcome. We have been building a base for advanced topics. Also, this info can be fused with any Japanese (JP) Healing, Wellness Plans / Other Reiki /and Yoga practices.
Power Awareness,
Our Defense.
Situations like Destiny Swapping even Evil Eyes are “stealing realities”. It’s causing your hard earned luck to switch out. Either way, it’s cancelling your reality all together. This maybe common recently over the last decade? I noticed it’s a sly easy move to make. Then, we are left wounded, suffering, accepting endless bad luck. It’s time to Power Up. This can be (very) private and quiet. However; building resources/EDU/self care for empowering is your business/your right. It’s a new found power we all can use for healing.
Stressin out-II
“Baby, Calm down, Calm Down.” - Song by Rema, Selena Gomez (Video Premiered Sep 7, 2022)
Within Virtual Work and VR Sims (Secondlife Metaverse) I love catching “Calm Down” On the radio streams. I love Selena first. Second, It’s such a catchy song with an island feel. This blends with both VR and working remotely.
Its also, a good affirmation or mantra to *Calm down* lol.
Something we reviewed in earlier Workshops.
I rarely mention love and relations but theres one caution.
When we date, almost marry an energy drainer/vampire partner; We enter doorways of no return. That person can psychic drain U during/after the relationship. They can also unleash their demons. Their dark energies (chi) can attach itself to you. It’s SYFI but common. Also, involving again, energy awareness. We are suppose to keep our love life sacred. But, Trust accidents do happen. The Energies can linger on. Also, Reiki can heal any breakup damage...
(See Pres for more info. Thx)
Christian education is an important element in forming moral values, ethical Behaviour and
promoting social unity, especially in diverse nations like in the Caribbean. This study examined
the impact of Christian education on the moral growth in the Caribbean, characterized by
significant Christian denomination, like the Orthodox, Catholic, Methodist, Lutheran and
Pentecostal. Acknowledging the historical and social intricacies in the Caribbean, this study
tends to understand the way in which Christian education mold ethical decision making, influence interpersonal relationships and promote communal values. These studies’ uses, qualitative and quantitative research method to conduct semi-structured interviews for twenty
(25) Church respondents which cut across different age groups and genders in the Caribbean. A
thematic analysis was utilized to identify recurring themes related to ethical Behaviour, communal values and moral development. The study analyses the three objectives of the study:
how Christian education Mold’s ethical Behaviour and enhance communal values, the role of
Christian educating in promoting ecumenism and the effect of Christian education on moral
development. Moreover, the findings show that Christian education serves as a fundamental role
for personal moral evaluation, instilling a well-structured moral value, promoting good
Behaviour and communal responsibility such as integrity, compassion, love and respect. However, the study also highlighted challenges including biases in Christian teachings, exclusivity and misconceptions about certain practices, which impede the actualization of
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...wygalkelceqg
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
How to Configure Add to Cart in Odoo 18 WebsiteCeline George
In this slide, we’ll discuss how to configure the Add to Cart functionality in the Odoo 18 Website. This feature enhances the shopping experience by offering three flexible options: Stay on the Product Page, Go to the Cart, or Let the User Decide through a dialog box.
How to Create Time Off Request in Odoo 18 Time OffCeline George
Odoo 18 provides an efficient way to manage employee leave through the Time Off module. Employees can easily submit requests, and managers can approve or reject them based on company policies.
Dashboard Overview in Odoo 18 - Odoo SlidesCeline George
Odoo 18 introduces significant enhancements to its dashboard functionalities, offering users a more intuitive and customizable experience. The updated dashboards provide real-time insights into various business operations, enabling informed decision-making.
How to Use Owl Slots in Odoo 17 - Odoo SlidesCeline George
In this slide, we will explore Owl Slots, a powerful feature of the Odoo 17 web framework that allows us to create reusable and customizable user interfaces. We will learn how to define slots in parent components, use them in child components, and leverage their capabilities to build dynamic and flexible UIs.
Based in Wauconda, Diana Enriquez teaches dual-language social studies at West Oak Middle School, guiding students in grades 6-8. With a degree from Illinois State University and an ESL/Bilingual certification, she champions diversity and equity in education. Diana’s early experience as a special education paraprofessional shaped her commitment to inclusive and engaging learning.
The PDF titled "Critical Thinking and Bias" by Jibi Moses aims to equip a diverse audience from South Sudan with the knowledge and skills necessary to identify and challenge biases and stereotypes. It focuses on developing critical thinking abilities and promoting inclusive attitudes to foster a more cohesive and just society. It defines bias as a tendency or prejudice affecting perception and interactions, categorizing it into conscious and unconscious (implicit) biases. The content highlights the impact of societal and cultural conditioning on these biases, particularly within the South Sudanese context.
3. operator
An operator is a symbol that performs operation. Operator acts on
variables or constants known as operands. If operator acts on single
operand then it is called as unary and if acts on two operands then it is
called as binary and when acts on three operands it is called as ternary
operator.
Operators are classified depending upon their nature as..
5. Arithmetic operator
performs basic arithmetic operation like addition, subtraction, multiplication and division.
Lets assume a=13 and b=5
operator Meaning Example Result
+ addition a+b 18
- subtraction a-b 8
* multiplication a*b 65
/ division a/b 2.6
% Modulus(remainder) a%b 3
** Exponent operator a**b 371293
// Integer division a//b 2
TEST1
Writes a python program to perform all arithmetic operations on two variable
a=20 and b=6
6. Priority to arithmetic operators
1.parentheses
2.exponent
3.multiplication,division,modulus and floor division are at equal priority
4.Addition and subtraction
5.Assignment
Evaluate the following arithmetic expression
d=(1+2)*3**2//2+3
7. Assignment Operator
stores the right side value to left side variable. Short hand assignments operators
used to perform arithmetic operations and stores the result to left side variable.
X=20, y=10 and z=5
Operator Example Meaning Result
= z=x+y Assignment operator z=30
+= z+=x
(z=z+x)
Shorthand addition
assignment operator
z=25
-= z-=x
(z=z-x)
Shorthand subtraction
Assignment operator
z=-15
*= z*=x
z=z*x
Shorthand
multiplication operator
z=100
/= z/=x
z=z/x
Shorthand division
operator
Z=0.25
%= z%=x
z=z%x
Shorthand modulus
operator
Z=5
**= z**=y
z=z**y
Shorthand Exponent
assignment operator
Z=9765625
//= z//=y
z=z//y
Shorthand division
assignment operator
0
8. Contd..
TEST2
Write python program to perform arithmetic operation on x=“20”
and y=0xad using shorthand assignment operator
Guess the output
a=b=1
print(a,b)
a=1;b=2
print(a,b)
a,b=1,2
print(a,b)
Note: python does not support increment(++) and decrement operator
9. Unary Minus Operator
The symbol – is used as unary minus operator. This operator is used
before a variable, its value is negated. That means if the variable value
is positive, it will be converted into negative and vice versa.
Example:
N=10
print(-N) output: -10
Num=-10
Num=-Num
print(Num) output: 10
10. Relational Operators
these operators are used for comparison of values. They returns Boolean value True or False.
a=1 and b=2
Operator Example Meaning Result
> a>b Greater than operator False
>= a>=b Greater than or equal to
operator
False
< a<b Less than operator True
<= a<=b Less than or equal to True
== a==b Equals to operator False
!= a!=b Not equals operator True
11. Contd..
Relational operators can be chained. It means a single expression can
hold more than one relational operators
Guess the output
x=15
print(10<x<20)
print(10>=x<20)
print(1<2<3<4)
print(1<2>3<4)
print(4>2>=2>1)
12. Logical operator
Logical operators are used to construct compound condition. A
compound condition is a combination of more than one simple
condition. Each of the simple condition is evaluated to True or False and
then the decision is taken to know whether total condition is True or
False. a=10,b=20,c=3,d=5
operator Example Meaning Result
and a>b and c>d Logical and False
or a>b or c<d Logical or True
not not a>b Logical not True
13. Boolean Operators
There are three Boolean operators which results True or False.
x=True y=False
operator Example meaning result
and x and y If both are true
then it returns true
otherwise false
False
or x or y If either x or y is
True then it returns
True else False
True
not not x If x is True it returns
False else True.
False
14. Guess the output
x=10; y=0
print(x and y) # if x and y both evaluated as true then y is returned true
# if x is true and y is false then y is returned
print(x or y)
print(not x)
print(not y)
OUTPUT
0
10
False
True
15. Bitwise operator
operates on individual bits ( 0 and 1) of the operands. They can operates on binary
number or integers.
Complement operator(~)
AND operator(&)
OR operator(|)
XOR operator(^)
Left shift operator(<<)
Right shift operator(>>)
16. Contd..
Complement of given number is returned by toggling the bits.
Example:
x=10
X=10=0000 1010
print(~x,bin(~x))
print(~b,bin(~b))
Output
-11 ( 1111 0101)
17. AND Operator(&)
x=10=0000 1010
y=11=0000 1011
x&y=0000 1010 (10)
example
x=10; b=15
print(x & b, bin(x &b))
x=0b1001;x=0b1001
print( x & b, bin( x & b) )
Output:
18. Bitwise OR Operator(|)
x=10=0000 1010
y=11=0000 1011
X|y=0000 1011 (15)
example
x=10;b=15
print(x | b, bin(x | b))
x=0b1001;b=0b1001
print( x | b, bin( x | b) )
Output
15 0b1111
9 0b1001
20. Bitwise left shift operator(<<): shifts the bits of the number
towards left specified number of positions.
x=10
X<<2
0 0 0 0 1 0 1 0
0 0 0 1 0 1 0 0 ( first time shift)
0 0 1 0 1 0 0 0 ( second time shift) (40)
Example
x=10
print(x<<2, bin(x<<2))
x=0b1001
print(x<<1,bin(x<<1))
Output
40 0b101000
21. Bitwise right shift operator(>>): shifts the bits of
the number towards right specified number of positions.
x=10
X>>2
0 0 0 0 1 0 1 0
0 0 0 0 0 1 0 1 ( first time shift)
0 0 0 0 0 0 1 0 ( second time shift) (2)
Example
x=10
print(x>>2, bin(x>>2))
x=0b1001
print(x>>1,bin(x>>1))
Output
2 0b10
4 0b100
22. Membership operators: to test a member is in
sequence such as list, string, tuple and dictionary
in operator: it returns True if an element is found in specified sequence otherwise returns False.
Example:
City=[‘Belagum’, ‘Bombay’, ’Mysore’ , ‘Lucknow’]
for k in City:
print(k)
If ‘Mysore’ in City:
print(“yes”)
else:
print(“no”)
Output
Belagum
Bombay
Mysore
Lucknow
yes
23. Contd..
not in operator: Works in reverse manner for in operator. This operator
returns True if an element is not found in the sequence
City=["Belagum" , "Bombay" , "Mysore" , "Lucknow"]
if "Mysore" not in City:
print("yes")
else:
print("no")
Output:
no
24. Identity Operator
The memory location of object can be seen using the id() function. This
function returns an integer number called the identity number that
internally represents the memory location of the object.
a=25
b=25
print(id(a),id(b))
b=47
print(id(a),id(b))
Output
140731879209504 140731879209504
140731879209504 140731879210208
25. The is operator
is operator compare whether two objects identity numbers are same or not. If
same it returns True otherwise False.
a=25
b=25
if a is b:
print("Both have same identity")
else:
print("They do not have same identity")
Output
Both have same identity
26. is not operator
If the identity numbers of two objects being compared are not same then it
returns True otherwise False.
a=25
b=35
if a is not b:
print("They do not have same identity")
else:
print("Both have same identity")
Output
They do not have same identity
27. Operator precedence and associativity
operator Name
() Parenthesis
** Exponentiation
-,~ Unary minus, bitwise complement
*, /,//,% Multiplication, division, floor division, modulus
+,- Addition, subtraction
<<,>> Bitwise left shift, bitwise right shift
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
>,>=,<,<=,==,!= Relational operators
28. Contd..
Operator Meaning
=, %=,/=,//=,-=,+=,*=,**= Assignment operators
Is, is not Identity operators
In, not in Membership operator
not Logical not
or Logical or
and Logical
Associativity: In an expression if we have more than one operators with same
priority then we have to flow the associativity of a operator. Associativity operator
is either from left to right or right to left. All operators have the associativity from
left to right except assignment operator.
30. Mathematical Functions
Functions Description
ceil(x) Raises x value to the next higher integer. If x is integer then same value is returned
ceil(4.5) gives 5
floor(x) Decreases x value to the previous integer value. If x is integer then the same value is
returned. floor(4.5) gives 4
degree(x) Converts angle value x from radians into degrees
degree(3.142) gives 179.999
radians(x) Converts x value from degrees into radians
radians(180) gives 3.142
sin(x) Gives sine value of x. Here x value is given in radians.
sin(0.5) gives 0.4794
cos(x) Gives cosine value of x. Here x value is given in radians.
cos(0.5) gives 0.87758
tan(x) Gives tangent value of x. Here x value is given in radians.
tan(0.5) gives 0.5463
exp(x) returns exponentiation of x. This is same as e **x
exp(0.5) returns 1.64872
31. Function Description
fabs(x) Gives the absolute value of x
fabs(-4.56) gives 4.56
factorial(x) Returns factorial value of x. Raises value error if x is not integer or is negative
factorial(4) gives 24
fmod(x,y) Returns remainder of division of x and y. fmod() is preferred to calculate modulus
for float values than % operator. It works well for integer values.
fmod(14.5,3) gives 2.5
fsum(values) Returns accurate sum of floating point values
fsum([1.5,2.4,-3.3]) returns 0.6000
modf(x) Returns float and integral part of x
modf(2.56) gives(0.56,2.0)
Log10(x) Returns logarithm of x for base 10
Log10(5.2345) gives 0.71888
Log(x,[base]) Returns the natural logarithm of x of specified base
log(5.5,2) gives 2.45943
Sqrt(x) Returns positive square root value of x
Sqrt(49) gives 7
32. Function Description
pow(x,y) Raises x value to the power of y
pow(5,3) returns 125.0
gcd(x,y) Gives greatest common divisor of x and y. Available from
python 3.5 onwards
gcd(25,30) gives 5
trunc(x) The real value of x is truncated to integer value and returned
trunc(15.5676) gives 15
isinf(x) Returns True if x is a positive or negative infinity and False
otherwise.
num=float(‘inf’) #num is a float number that indicates infinity
print(isinf(num)) gives True
Isnan(x) Returns True if x is a NaN(not a number) and False otherwise
num=float(‘NaN’) #converts NaN into a float representation
print(isnan(num)) gives True
33. Constants in Math Module
Constant Description
pi The mathematical constant pi value 3.141592
e e= 2.718281
inf A floating point positive infinity. For negative infinity use –
math.inf
nan A floating point not a number (NaN) value
To use these constants and math built functions we should import math module
import math
b=math.sqrt(10)
or
from math import sqrt
b=sqrt(10)
34. Programs on mathematical functions
Write a python program to calculate area of circle
#python program to find area of a circle
import math
r=4.5
area= math.pi * math.pow (r,2)
print("Area of a circle", math.floor(area))
Output
Area of a circle 63