You are on page 1of 4

DAY3 ASSIGNMENT

>> CONTROL STATEMENTS

1) SELECTIVE STATEMENTS
a) if 
b) if-else
c) if-else-if (nested if-else)
d) if-else ladder

2) ITERATIVE STATEMENTS (looping)


A) for loop: A for loop is used to iterate over a sequence like lists,
type, dictionaries, sets, or even strings.Loop
statements will be executed for each item of the
sequence.

Syntax of for loop:

for item in iterator:


statements(code)

eg. nums = []
for i in range(1, 11):
print(nums)

B) while loop: It continually executes the statements(code) as


long as the given condition is TRUE. It first checks the condition
and then jumps into the instructions.

Syntax:
while condition
statements(code)
Eg. num = 1
even_numbers = []
while num <= 10:
if num % 2 == 0:
even_numbers .append(num)
num += 1
print("Even Numbers list: ", even_numbers )

3) JUMPING STATEMENTS
a) break
b) continue
c) pass
d) return
e) exit
etc.

>> Array

 Python arrays are a data structure like lists.


 They contain a number of objects that can be of different data
types.
 Python arrays can be iterated and have a number of built-in
functions to handle them
 Arrays give us a way to store and organize data, and we can use
the built-in Python methods to retrieve or change that data. For
example, if you have a list of student names that you want to
store, you may want to store them in an array
 Arrays are useful if you want to work with many values of the
same Python data type. This might be student names, employee
numbers, etc. They allow you to store related pieces of data that
belong. And they make it easy to perform the same operation on
multiple values at the same time.
 basic syntax to declare an array in Python:

students = ['Alex', 'Bill', 'Catherine', 'Andy', 'Molly', 'Rose']

print(students)

Output: ['Alex', 'Bill', 'Catherine', 'Andy', 'Molly', 'Rose']

 Because each item has its own index number, we can access each
item in our array. We can do so by calling our list and specifying
an index number, like so:

print(students[2])
output : "Catherine"

 Methods:

o append(): Adds an item to an array


o pop(): Removes an item from an array
o clear(): Removes all items from an array
o copy(): Returns a copy of an array
o count(): Returns the number of elements in a list
o index(): Returns the index of the first element with a specific value
o insert(): Adds an element to the array at a specific position
o reverse(): Reverses the order of the array
o sort(): Sorts the list

NUMPY - NUMERIC PYTHON


SIX DIFFERENT WAYS TO WORK WITH NUMPY ARRAY
 array()
 linspace()
 logspace()
 arange()
 zeros()
 ones()

You might also like