0% found this document useful (0 votes)
12 views9 pages

Collection and Operator Question

Uploaded by

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

Collection and Operator Question

Uploaded by

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

What is Python?

Python is a popular programming language. It was created by Guido van


Rossum, and released in 1991.

It is used for:

 web development (server-side),


 software development,
 mathematics,
 system scripting.

What can Python do?


 Python can be used on a server to create web applications.
 Python can be used alongside software to create workflows.
 Python can connect to database systems. It can also read and modify
files.
 Python can be used to handle big data and perform complex
mathematics.
 Python can be used for rapid prototyping, or for production-ready
software development.

Why Python?
 Python works on different platforms (Windows, Mac, Linux, Raspberry
Pi, etc).
 Python has a simple syntax similar to the English language.
 Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
 Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be
very quick.
 Python can be treated in a procedural way, an object-oriented way or a
functional way.

Python Indentation
Indentation refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for


readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.

Python Numbers
There are three numeric types in Python:

 int
 float
 complex

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"')

How does compilation Happen in Python

How does memory management happen in Python

What is the difference between List and Tuple Or set/dictionary

Why tuple is more faster then list

What is the difference between mutable and immutable

Python Operators
Operators are used to perform operations on variables and values.

In the example below, we use the + operator to add together two values:
 Arithmetic operators
 Assignment operators
 Relational operators
 Logical operators
 Identity operators
 Membership operators
 Bitwise operators

Python Arithmetic Operators


Arithmetic operators are used with numeric values to perform common
mathematical operations:

Operator Name Example

+ Addition x+y

- Subtraction x-y

* Multiplication x*y

/ Division x/y

% Modulus x%y

** Exponentiation x ** y

// Floor division x // y
Python Assignment Operators
Assignment operators are used to assign values to variables:

Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3

%= x %= 3 x=x%3

//= x //= 3 x = x // 3

**= x **= 3 x = x ** 3

&= x &= 3 x=x&3


|= x |= 3 x=x|3

^= x ^= 3 x=x^3

>>= x >>= 3 x = x >> 3

<<= x <<= 3 x = x << 3

:= print(x := 3) x=3
print(x)

Python Comparison Operators


Comparison operators are used to compare two values:

Operator Name Example

== Equal x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y


>= Greater than or equal to x >= y

<= Less than or equal to x <= y

Python Logical Operators


Logical operators are used to combine conditional statements:

Operator Description Example

and Returns True if both statements are true x < 5 and

or Returns True if one of the statements is true x < 5 or x

not Reverse the result, returns False if the result is not(x < 5
true

Python Identity Operators


Identity operators are used to compare the objects, not if they are equal, but
if they are actually the same object, with the same memory location:
Operator Description Exampl

is Returns True if both variables are the same x is y


object

is not Returns True if both variables are not the same x is not
object

Python Membership Operators


Membership operators are used to test if a sequence is presented in an
object:

Operator Description Ex

in Returns True if a sequence with the specified value is x


present in the object

not in Returns True if a sequence with the specified value is not x


present in the object

Python Bitwise Operators


Bitwise operators are used to compare (binary) numbers:

Operato Name Description


r

& AND Sets each bit to 1 if both bits are 1

| OR Sets each bit to 1 if one of two bits is 1

^ XOR Sets each bit to 1 if only one of two bits is 1

~ NOT Inverts all the bits

<< Zero fill left Shift left by pushing zeros in from the right and let the
shift leftmost bits fall off

>> Signed right Shift right by pushing copies of the leftmost bit in from the
shift left, and let the rightmost bits fall off

Operator Description

() Parentheses

** Exponentiation

+x -x ~x Unary plus, unary minus, and bitwise NOT


* / // % Multiplication, division, floor division, and modulus

+ - Addition and subtraction

<< >> Bitwise left and right shifts

& Bitwise AND

^ Bitwise XOR

| Bitwise OR

== != > >= < <= is is not in not Comparisons, identity, and membership operators
in

not Logical NOT

and AND

or OR

You might also like