You are on page 1of 9

09-Nov-2021

DAY 2 ASSINGMENT

>> IDLE Introduction


 IDLE stands for Integrated Development and Learning
Environment.
 IDLE comes bundled with the default implementation of the
Python language.
 It allows programmers to easily write Python code.
 Just like Python Shell, IDLE can be used to execute a single
statement and create, modify, and execute Python scripts.
 IDLE is a very simple and sophisticated IDE developed primarily for
beginners
 Because of its simplicity, it is highly considered and recommended
for educational purposes.
 Some of the key features it offers are:
o Python shell with syntax highlighting
o Multi-window text editor
o Code auto completion
o Intelligent indenting
o Program animation and stepping which allows one line of code to
run at a time helpful for debugging
o Persistent breakpoints
o Call stack visibility

>> Arithmetic Operators


It is a python operator used for basic mathematical operations like:
 Addition (+) Add the values on either side of the operator.
Eg. >>> 3+4
Output: 7
09-Nov-2021

 Subtraction (-) Subtracts the value on the right from the one on
the left.
Eg. >>> 3-4
Output: -1
 
 Multiplication (*) Multiplies the values on either side of the
operator.
Eg. >>> 3*4
Output: 12

 Division (/) Divides the value on the left by the one on the right.
Notice that division results in a floating-point value.
Eg. >>> 3/4
Output: 0.75

 Exponentiation (**) Raises the first number to the power of the


second.
Eg. >>> 3**4
Output: 81

 Floor Division (//) Divides and returns the integer value of the
quotient. It dumps the digits after the decimal.
Eg. >>> 3//4
>>> 4//3
Output: 1
>>> 10//3
Output: 3

 Modulus (%) Divides and returns the value of the remainder.


Eg. >>> 3%4
Output: 3

>>> 10.5%3
09-Nov-2021

Output: 1.5

>> ID & type


 ID() is an inbuilt function in Python. The function accepts a single
parameter and is used to returns a unique id for the specified object.
The id is assigned to the object when it is created.
The id is the object's memory address, and will be different for each
time you run the program. (Except for some object that has a constant
unique id, like integers from -5 to 256)
Eg.x = ('apple', 'banana', 'cherry')
y = id(x)
print(y)
Output: 56770517

 Type() function returns the type of the specified object or returns a


new type object of the specified dynamic class, based on the
specified class name, base classes and class body.
Syntax:
type(object)
type(name, bases, dict)

Parameters:
1. object: Required. The object whose type is to be returned.
2. name: Required. A class name.
3. bases: Required. A tuple that itemizes the base class.
4. dict: Required. A dictionary which is the namespace containing
definitions for the class body.
Eg. a = ('apple', 'banana', 'cherry')
b = "Hello World"
c = 33

x = type(a)
y = type(b)
09-Nov-2021

z = type(c)

print(x)
print(y)
print(z)

Output: <class 'tuple'>


<class 'str'>
<class 'int'>

>> String Operations


String operators represent the different types of operations that can be
employed on the program’s string type of variables. Python allows
several string operators that can be applied on the python string are as
below:
 Assignment operator: “=.”
Eg.
string1 = ”hello"
string2 = 'hello'
string3 = '''hello'''
print(string1)
print(string2)
print(string3)
 Concatenate operator: “+.”
Eg.
string1 = "hello"
string2 = "world "
string_combined = string1+string2
print(string_combined)
 String repetition operator: “*.”
Eg.
string1 = "helloworld"
print(string1*2)
09-Nov-2021

print(string1*3)
print(string1*4)
print(string1*5)
 String slicing operator: “[]”
Eg.
string1 = "helloworld"
print(string1[1])
print(string1[-3])
print(string1[1:5])
print(string1[1:-3])
print(string1[2:])
print(string1[:5])
 String comparison operator: “==” & “!=”
Eg.
string1 = "hello"
string2 = "hello, world"
string3 = "hello, world"
string4 = "world"
print(string1==string4)
print(string2==string3)
print(string1!=string4)
print(string2!=string3)
Output: false
True
True
false
 Membership operator: “in” & “not in”
Eg.
string1 = "helloworld"
print("w" in string1)
print("W" in string1)
print("t" in string1)
print("t" not in string1)
09-Nov-2021

print("hello" in string1)
print("Hello" in string1)
print("hello" not in string1)

Output: true
False
False
True
True
False
False
 Escape sequence operator: “\.”

 String formatting operator: “%”

>> LIST with functions


 A list is defined as an ordered, mutable, and heterogeneous
collection of objects.
 Mutable means the list can be mutated or changed, and
heterogeneous implies that you’ll be able to mix and match any
kind of object, or data type, within a list (int, float, or string).
 Lists are contained within a collection of square brackets [ ].
 the subsequent list functions:
o sort(): Sorts the list in ascending order.
o type(list): It returns the class type of an object.
o append(): Adds one element to a list.
o extend(): Adds multiple elements to a list.
o index(): Returns the first appearance of a particular value.
o max(list): It returns an item from the list with a max value.
o min(list): It returns an item from the list with a min value.
o len(list): It gives the overall length of the list.
o clear(): Removes all the elements from the list.
o insert(): Adds a component at the required position.
09-Nov-2021

o count(): Returns the number of elements with the required value.


o pop(): Removes the element at the required position.
o remove(): Removes the primary item with the desired value.
o reverse(): Reverses the order of the list.
o copy(): Returns a duplicate of the list.

>> TUPLE with functions


 The tuple() function is a built-in function in Python that can be
used to create a tuple.
 A tuple is an immutable sequence type.
 Tuples use parentheses
Function & Description
o len(tuple): Gives the total length of the tuple.
o count():
o Index():
o max(tuple): Returns item from the tuple with max value.
o min(tuple): Returns item from the tuple with min value.
o tuple(seq): Converts a list into tuple.

>> SET with functions


 Set in python is similar i.e. sets in mathematics
 Set in python does not support indexing
 Repetition of element is not allowed in set.
 Output of set comes in random order.
 {, } are used to represent set.
 Some of the Functions used are:
o add() Adds an element to the set
o clear(): Removes all the elements from the set
o copy(): Returns a copy of the set
o difference():Returns a set containing the difference between two or
more sets
o difference_update(): Removes the items in this set that are also
included in another, specified set
09-Nov-2021

o discard(): Remove the specified item


o intersection(): Returns a set, that is the intersection of two or more
sets
o intersection_update(): Removes the items in this set that
are not present in other, specified set(s)
o isdisjoint(): Returns whether two sets have a intersection or not
o issubset(): Returns whether another set contains this set or not
o issuperset(): Returns whether this set contains another set or not
o pop(): Removes an element from the set
o remove(): Removes the specified element
o symmetric_difference(): Returns a set with the symmetric
differences of two sets
o symmetric_difference_update(): inserts the symmetric differences
from this set and another
o union(): Return a set containing the union of sets
o update(): Update the set with another set, or any other iterable

>> Dictionary 
 A dictionary is an unordered and mutable Python container that
stores mappings of unique keys to values.
 Dictionaries are written with curly brackets ({}), including key-value
pairs separated by commas (,). A colon (:) separates each key from
its value.
 works on key value elements
Eg. products = {'table': 120, 'chair': 40, 'lamp': 14, 'bed': 250,
'mattress': 100}

>> HELP menu in IDLE


 Help menu (Shell and Editor)
 About IDLE: Display version, copyright, license, credits, and
more.
 IDLE Help: Display this IDLE document, detailing the menu
options, basic editing and navigation, and other tips.
09-Nov-2021

 Python Docs: Access local Python documentation, if installed, or


start a web browser and open docs.python.org showing the
latest Python documentation.
 Turtle Demo: Run the turtle demo module with example Python
code and turtle drawings.
 Additional help sources may be added here with the Configure
IDLE dialog under the General tab. See the Help sources
subsection below for more on Help menu choices.

>> CONTROL STATEMENTS

1) SELECTIVE STATEMENTS
A) IF-LESE
a) if 
b) if-else
c) if-else-if(nested if-else)
d) if-else ladder
2) ITERATIVE STATEMENTS (looping)
A) for loop
B) while loop
3) JUMPING STATEMENTS
a) break
b) continue
c) pass
d) return
e) exit
etc.

You might also like