This document provides instructions on installing Python 3 on Ubuntu and Windows operating systems. It discusses installing Python 3.8 on Ubuntu using the apt install command and verifying the installation with the python --version command. It also outlines downloading the Python installer, running the executable, adding Python to environment variables, and verifying the installation on Windows. The document further explains installing iPython using pip and provides examples of using boolean values, conditionals, loops, functions, and strings in Python programs.
Machine Learning With Python From Indiaâs Most Advanced Learnerâs Community. 200+ High-Quality Lectures. 4 Months Live Mentor-ship. 15+ Projects. Industry Insights.
Visit- https://insideaiml.com/course-details/Machine-Learning-with-Python-Statistics
Machine Learning With Python From Indiaâs Most Advanced Learnerâs Community. 200+ High-Quality Lectures. 4 Months Live Mentor-ship. 15+ Projects. Industry Insights.
Visit- https://insideaiml.com/course-details/Machine-Learning-with-Python-Statistics
In this PPT you will learn how to use looping in python.
For more presentation in any subject please contact us on
raginijain0208@gmail.com.
You get a new presentation every Sunday at 10 AM.
Learn more about Python by clicking on given below link
Python Introduction- https://www.slideshare.net/RaginiJain21/final-presentation-on-python
Basic concept of Python -https://www.slideshare.net/RaginiJain21/python-second-ppt
Python Datatypes - https://www.slideshare.net/RaginiJain21/data-types-in-python-248466302
Python Library & Module - https://www.slideshare.net/RaginiJain21/python-libraries-and-modules
Basic Python Programs- https://www.slideshare.net/RaginiJain21/basic-python-programs
Python Media Libarary - https://www.slideshare.net/RaginiJain21/python-media-library
Python is an interpreted, high-level, and general-purpose programming language.
It is an easy to learn general-purpose programing language.
It is a platform-independent programing language, which means it can be used on any machine and in any operating system.
It has a simple syntax
Python is a case sensitive language.
It is an interrupted language.
It is free to use and even free for commercial products.
In this chapter we are going to get familiar with recursion and its applications. Recursion represents a powerful programming technique in which a method makes a call to itself from within its own method body. By means of recursion we can solve complicated combinatorial problems, in which we can easily exhaust different combinatorial configurations, e.g. generating permutations and variations and simulating nested loops. We are going to demonstrate many examples of correct and incorrect usage of recursion and convince you how useful it can be.
Best Data Science Ppt using Python
Data science is an inter-disciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge and insights from many structural and unstructured data. Data science is related to data mining, machine learning and big data.
What is Data Type?
Primitive Types in C#: Integer Types, Floating-Point Types, Decimal Type, Boolean Type, Character Types, Strings, Objects
Value Types and Reference Types
Variables. Using Variables: Declaring, Initializing, Assigning Value, Accessing Value
Literals: The Values of the Variables in the Source Code. Boolean Literals. Integer Literals. Floating-Point Literals, Decimal Literals, String Literals and Escaping Sequences
Exercises: Working with Primitive Types and Variables
In this chapter we will get familiar with primitive types and variables in Java â what they are and how to work with them. First we will consider the data types â integer types, real types with floating-point, Boolean, character, string and object type. We will continue with the variables, with their characteristics, how to declare them, how they are assigned a value and what is variable initialization.
All data values in Python are encapsulated in relevant object classes. Everything in Python is an object and every object has an identity, a type, and a value. Like another object-oriented language such as Java or C++, there are several data types which are built into Python. Extension modules which are written in C, Java, or other languages can define additional types.
To determine a variable's type in Python you can use the type() function. The value of some objects can be changed. Objects whose value can be changed are called mutable and objects whose value is unchangeable (once they are created) are called immutable.
learn how to program with python
from scratch to be an expert
use the link in the first slide to get the full course
here is the link if you want : https://oke.io/JdxdUl
the link of the documentation : https://oke.io/J6DeY3
link to download python : https://oke.io/BENgRLR2
In this PPT you will learn how to use looping in python.
For more presentation in any subject please contact us on
raginijain0208@gmail.com.
You get a new presentation every Sunday at 10 AM.
Learn more about Python by clicking on given below link
Python Introduction- https://www.slideshare.net/RaginiJain21/final-presentation-on-python
Basic concept of Python -https://www.slideshare.net/RaginiJain21/python-second-ppt
Python Datatypes - https://www.slideshare.net/RaginiJain21/data-types-in-python-248466302
Python Library & Module - https://www.slideshare.net/RaginiJain21/python-libraries-and-modules
Basic Python Programs- https://www.slideshare.net/RaginiJain21/basic-python-programs
Python Media Libarary - https://www.slideshare.net/RaginiJain21/python-media-library
Python is an interpreted, high-level, and general-purpose programming language.
It is an easy to learn general-purpose programing language.
It is a platform-independent programing language, which means it can be used on any machine and in any operating system.
It has a simple syntax
Python is a case sensitive language.
It is an interrupted language.
It is free to use and even free for commercial products.
In this chapter we are going to get familiar with recursion and its applications. Recursion represents a powerful programming technique in which a method makes a call to itself from within its own method body. By means of recursion we can solve complicated combinatorial problems, in which we can easily exhaust different combinatorial configurations, e.g. generating permutations and variations and simulating nested loops. We are going to demonstrate many examples of correct and incorrect usage of recursion and convince you how useful it can be.
Best Data Science Ppt using Python
Data science is an inter-disciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge and insights from many structural and unstructured data. Data science is related to data mining, machine learning and big data.
What is Data Type?
Primitive Types in C#: Integer Types, Floating-Point Types, Decimal Type, Boolean Type, Character Types, Strings, Objects
Value Types and Reference Types
Variables. Using Variables: Declaring, Initializing, Assigning Value, Accessing Value
Literals: The Values of the Variables in the Source Code. Boolean Literals. Integer Literals. Floating-Point Literals, Decimal Literals, String Literals and Escaping Sequences
Exercises: Working with Primitive Types and Variables
In this chapter we will get familiar with primitive types and variables in Java â what they are and how to work with them. First we will consider the data types â integer types, real types with floating-point, Boolean, character, string and object type. We will continue with the variables, with their characteristics, how to declare them, how they are assigned a value and what is variable initialization.
All data values in Python are encapsulated in relevant object classes. Everything in Python is an object and every object has an identity, a type, and a value. Like another object-oriented language such as Java or C++, there are several data types which are built into Python. Extension modules which are written in C, Java, or other languages can define additional types.
To determine a variable's type in Python you can use the type() function. The value of some objects can be changed. Objects whose value can be changed are called mutable and objects whose value is unchangeable (once they are created) are called immutable.
learn how to program with python
from scratch to be an expert
use the link in the first slide to get the full course
here is the link if you want : https://oke.io/JdxdUl
the link of the documentation : https://oke.io/J6DeY3
link to download python : https://oke.io/BENgRLR2
Detailing about basics of C language and its control structure for learning C Language for beginners. It covers looping statement , control statement etc.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
How to Create Map Views in the Odoo 17 ERPCeline George
Â
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
Â
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
Â
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesarâs dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empireâs birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empireâs society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Â
Andreas Schleicher presents at the OECD webinar âDigital devices in schools: detrimental distraction or secret to success?â on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus âManaging screen time: How to protect and equip students against distractionâ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective âStudents, digital devices and successâ can be found here - https://oe.cd/il/5yV
Palestine last event orientationfvgnh .pptxRaedMohamed3
Â
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
2. Install Python 3 On Ubuntu
Prerequisites
Step 1.A system running Ubuntu
Step 2.A user account with sudo privileges
Step 3.Access to a terminal command-line (CtrlâAltâT)
Step 4.Make sure your environment is configured to use
Python 3.8
2
3. Install Python 3
Now you can start the installation of Python 3.8.
$sudo apt install python3.8
Allow the process to complete and verify the Python
version was installed successfully
$python ââversion
3
4. Installing and using Python on Windows is very simple.
Step 1: Download the Python Installer binaries
Step 2: Run the Executable Installer
Step 3: Add Python to environmental variables
Step 4: Verify the Python Installation
4
5. īPython Installationīŋ
īOpen the Python website in your web browser.
īhttps://www.python.org/downloads/windows/
īOnce the installer is downloaded, run the Python installer.
īAdd the following path
īC:Program FilesPython37-32: for 64-bit installation
īOnce the installation is over, you will see a Python Setup
Successful window.
īYou are ready to start developing Python applications in
your Windows 10 system.
5
6. īiPython Installationīŋ
īIf you already have Python installed, you can use pip to
install iPython using the following command:
$pip install iPython
īTo use it, type the following command in your computerâs
terminal:
$ipython
6
7. BOOLEAN VALUES
ī Boolean data type have two values. They are 0 and 1.
ī 0 represents False
ī 1 represents True
ī True and False are keyword.
Example:
>>> 3==5
False
>>> 6==6
True
>>> True+True
2
>>> False+True
1
>>> False*True
0
8. CONDITIONALS
ī Conditional if
ī Alternative ifâĻ else
ī Chained ifâĻelifâĻelse
ī Nested ifâĻ.else
Conditional (if)
ī conditional (if) is used to test a condition, if the condition is
true the statements inside will be executed.
Syntax:
if(conditions):
âĻâĻâĻâĻâĻ..
statements
âĻâĻâĻâĻâĻ..
9. CONDITIONALS
Flowchart
Example:
1. Program to provide discount Rs 500, if the purchase amount is greater
than 2000.
Program Output
purchase=eval(input(âenter your
purchase amountâ)
if(purchase>=2000):
purchase=purchase-500
print(âamount to payâ, purchase)
enter your purchase amount
2500
amount to pay
2000
10. CONDITIONALS
2.Program to provide bonus mark if the category is sports
Program Output
m=eval(input(âenter your markâ))
c=input(âenter your category G/Sâ)
if(c==âSâ):
m=m+5
print(âmark isâ,m)
enter your mark
85
enter your category G/S
S
mark is 90
11. CONDITIONALS
Alternative (if-else)
īIn the alternative the condition must be true or false.
īIn this else statement can be combined with if statement.
īThe else statement contains the block of code that executes when
the condition is false.
īIf the condition is true statements inside the if get executed
otherwise else part gets executed.
īThe alternatives are called branches.
syntax:
if (condition1):
statement1
else:
statement2
13. CONDITIONALS
.
Positive or negative number Output
n=eval(input("enter a number"))
if(n>=0):
print("positive number")
else:
print("negative number")
enter a number 8
positive number
Leap year or not Output
y=eval(input("enter a year"))
if(y%4==0):
print("leap year")
else:
print("not leap year")
enter a year 2000
leap year
14. CONDITIONALS
.
Greatest of two numbers Output
a=eval(input("enter a value:"))
b=eval(input("enter b value:"))
if(a>b):
print("greatestâ,a)
else:
print("greatest:",b)
enter a value:4
enter b value:7
greatest: 7
Eligibility for voting Output
age=eval(input("enter your age:"))
if(age>=18):
print("you are eligible for vote")
else:
print("you are eligible for vote")
enter ur age:78
you are eligible for vote
15. CONDITIONALS
Chained conditionals(if-elif-else)
īThe elif is short for else if.
īThis is used to check more than one condition.
īIf the condition1 is false, it checks the condition2 of the elif block.
īIf all the conditions are false, then the else part is executed.
īOnly one part is executed according to the condition.
īThe if block can have only one else block. But it can have multiple
elif blocks.
īThe way to express a computation like that is a chained conditional.
18. SAMPLE PROGRAMS
.
Student mark system Output
mark=eval(input("enter your mark:"))
if(mark>=90):
print("grade:S")
elif(mark>=80):
print("grade:A")
elif(mark>=70):
print("grade:B")
elif(mark>=50):
print("grade:C")
else:
print("fail")
Enter your mark:78
grade:B
Roots of quadratic equation Output
a=eval(input("enter a value:"))
b=eval(input("enter b value:"))
c=eval(input("enter c value:"))
d=(b*b-4*a*c)
if(d==0):
print("same and real roots")
elif(d>0):
print("diffrent real roots")
else:
print("imaginagry roots")
enter a value:1
enter b value:0
enter c value:0
same and real roots
19. CONDITIONALS
Nested conditionals
īOne conditional can also be nested within another.
īAny number of condition can be nested inside one another.
īIf the condition is true it checks another ifcondition1.
Syntax: Flowchart:
if (condition1):
if(condition2):
statement1
else:
statement2
else:
statement3
20. SAMPLE PROGRAMS
.
Greatest of three numbers Output
a=eval(input("enter the value of a"))
b=eval(input("enter the value of b"))
c=eval(input("enter the value of c"))
if(a>b):
if(a>c):
print("the greatest no is",a)
else:
print("the greatest no is",c)
else:
if(b>c):
print("the greatest no
is",b)
else:
print("the greatest no is",c)
Enter your mark:78
grade:B
21. ITERATION
1.while
2.for
while loop
īWhile loop is used to repeatedly executes set of statement as
īlong as a given condition is true.
īIn while loop, test expression is checked first. The body of the loop
is entered only if the test expression is True.
īThis process continues until the test expression evaluates to False.
īThe body of the while loop is determined through indentation.
īThe statements inside the while start with indentation
23. ITERATION
else in while loop
The else part will be executed when the condition become false.
Example
i=1
while(i<=5):
print(i)
i=i+1
else:
print("the number greater than 5")
Output
1
2
3
4
5
the number greater than 5
24. ITERATION
Nested while
īWhile inside another while is called nested while
Syntax:
While(condition1):
while(condtion2):
statement2
Statement1
Example
i=1
while i<4:
j=4
while j<6:
print(i*j)
j=j+1
i=i+1
output
4
5
8
10
12
15
25. ITERATION
for loop(for in range)
īWe can generate a sequence of numbers using range() function.
īrange(10) will generate numbers from 0 to 9 (10 numbers).
īIn range function have to define the start, stop and step size as
range(start,stop,step size).
īstep size defaults to 1 if not provided.
Syntax:
for i in range(start, stop, steps):
body of the for loop
Example:
for i in range(1,6):
print(i)
Flowchart
Output
1 2 3 4 5
26. ITERATION
else in for loop
īThe else statement is executed when the loop has reached the limit.
īThe statements inside for loop and statements inside else will also
execute.
Example:
for i in range(1,6):
print(i)
else:
print("the number greater than 6")
Output
1
2
3
4
5
the number greater than 6
27. ITERATION
for in sequence
īThe for loop in Python is used to iterate over a sequence (list, tuple,
string).
īIterating over a sequence is called traversal.
īLoop continues until we reach the last element in the sequence.
īThe body of for loop is separated from the rest of the code using
indentation.
Syntax:
for i in sequence:
print(i)
28. ITERATION
Sequence can be a list, strings or tuples
No. Sequences Example Output
1 for loop in string for in in âRAJAâ
print(i)
R
A
J
A
2. for loop in list for i in [2,3,5,6,9]
print(i)
2
3
5
6
9
3. for loop in tuple for i in (2,3,1):
print(i)
2
3
1
29. ITERATION
Nested for loop
īfor inside another for is called nested for.
Syntax
for i in sequence:
for j in sequence:
statements
statements
Example:
for i in range(1,4):
for j in range(4,7):
print(i*j)
Output
4
5
6
8
10
12
12
15
18
30. Assignments
Programs
1. print nos divisible by 5 not by 10:
2. Program to print fibonacci series.
3. Program to find factors of a given number
4. check the given number is perfect number or not
5. check the no is prime or not
6. Print first n prime numbers
7. Program to print prime numbers in range
31. LOOP CONTROL STRUCTURES
1.break 2.continue 3.pass
1.break
īTo end a while loop prematurely, the break statement can be used.
īWhen encountered inside a loop, the break statement causes the
loop to finish immediately.
Syntax : break Flowchart
while(test expression)
if(condition):
break
Example
i = 0
while 1==1:
print(i)
i = i + 1
if i >= 5:
print("Breaking")
break
print("Finished")
Output
0
1
2
3
4
Breaking
Finished
32. LOOP CONTROL STRUCTURES
2.continue
īIt is unlike break, continue jumps back to the top of the loop, rather
than stopping it.
īAnother statement that can be used within loops is continue.
Syntax : continue Flowchart
while(test expression):
if(condition):
continue
Example
i = 0
while True:
i = i +1
if i == 2:
print("Skipping 2")
continue
if i == 5:
print("Breaking")
break
print(i)
print("Finished")
Result:
>>>
1
Skipping
2
3
4
Breaking
Finished
>>>
33. LOOP CONTROL STRUCTURES
3.pass
īIt is a null statement, nothing happens when it is executed.
Syntax : pass
for i in sequence:
if(condition):
pass
Example
for i in "welcome":
if (i == "c"):
pass
print(i)
Result:
>>>
w
e
l
c
o
m
e
>>>
34. SCOPE OF VARIABLES
Global scope
īThe scope of a variable refers to the places that you can see or
access a variable.
īA variable with global scope can be used anywhere in the program.
īIt can be created by defining a variable outside the function.
Example
a=50 #Global variable
def add():
b=20
c=a+b
print(c)
def sub():
b=30
c=a-b
print(c)
add()
sub()
print(a)
Result:
>>>
70
20
50
>>>
35. SCOPE OF VARIABLES
Local scope
īA variable with local scope can be used only within the function .
Example
a=50 #global variable
def add():
b=20 #local variable
c=a+b
print(c)
def sub():
b=30
c=a-b
print(c)
add()
sub()
print(a)
print(b)
Result:
>>>
70
20
50
error
>>>
36. FUNCTION COMPOSITION
īIt is the ability to call one function from within another function
īIt is a way of combining functions such that the result of each
function is passed as the argument of the next function.
īThe output of one function is given as the input of another function is
known as function composition.
Example
def max(x, y):
if x >=y:
return x
else:
return y
print(max(4, 7))
z = max(8, 5)
print(z)
Result:
>>>
7
8
>>>
37. RECURSION
īA function calling itself till it reaches the base value.
#Factorial of a given number
def fact(n):
if(n==1):
return 1
else:
return n*fact(n-1)
n=eval(input("enter no:"))
fact=fact(n)
print("Fact is",fact)
Result:
>>>
enter no:5
Fact is 120
>>>
38. STRINGS
īIt is defined as sequence of characters represented either single
quotes (' ') or double quotes (" ").
īAn individual character in a string is accessed using a index.
īThe index should always be an integer (positive or negative).
īAn index starts from 0 to n-1.
īStrings are immutable i.e. the contents of the string cannot be
changed after it is created.
īPython will get the input at run time by default as a string.
īPython does not support character data type. A string of size 1 can
be treated as characters.
40. STRINGS
Indexing
>>>a= HELLO
>>>print(a[0])
>>>H
>>>print(a[-1])
>>>O
Positive indexing helps in accessing the string from
the beginning
Negative subscript helps in accessing the string from
the end.
Slicing
print a[0:4]-HELL
print a[ :3]-HEL
print a[0: ]-HELLO
The Slice[start : stop] operator extracts sub string
from the strings.
A segment of a string is called a slice.
Concatenation
a= âthamâ
b=âmanâ
>>>print(a+b)
thamman
+ operator joins the text on both sides of the operator.
Repetitions
a= âRAJâ
>>>print(3*a)
RAJRAJRAJ
* operator repeats the string.
Membership
>>> s="WELCOME"
>>>"E" in s
True
>>> "a" not in s
True
Check a particular character is in string or not.
Returns true if present.
41. STRINGS
Immutability
īStrings are immutable as they cannot be changed after they are
created.
ī[ ] operator cannot be used on the left side of an assignment.
Element
assignment
A=âPYTHONâ
A[0]=âXâ
Element assignment error
Element deletion
A=âPYTHONâ
del A[0]
Element deletion error
Delete a string
A=âPYTHONâ
del A
print(A)
A is not defined
42. STRINGS
String built-in functions and methods
īA method is a function that belongs to an object.
Syntax: stringname.method(), a=âhappy birthdayâ
Syntax Example Description
a.capitalize()
>>> a.capitalize()
' Happy birthday
capitalize only the first letter in a
string
a.upper()
>>> a.upper()
'HAPPY BIRTHDAY
change string to upper case
a.lower()
>>> a.lower()
' happy birthday
change string to lower case
a.title()
>>> a.title()
' Happy Birthday '
change string to title case
a.isupper()
A= happy birthday
>>> a.isupper()
False
whether letters are upper case or
not
a.islower()
>>> a.islower()
True
whether letters are lower case or
not
len(a)
>>>len(a)
>>>14
length of the string
43. STRING MODULES
īA module is a file containing python definitions, functions,
statements.
īStandard library of python is extended as modules.
īProgrammer needs to import the module.
īWe can use to any of its functions or variables in our code.
īLarge number of standard modules also available in python.
īStandard modules can be imported the same way as we import our
user-defined modules.
Syntax:
import module_name
45. ARRAY
īArray is a collection of similar elements. Elements in the array can
be accessed by index. Index starts with 0. Array can be handled in
python by module named array.
īTo create array have to import array module in the program.
Syntax :
import array
Syntax to create array:
array_name = module_name.function_name( datatype ,[elements])
Example:
a=array.array(i,[1,2,3,4])
a- array name
array- module name
i- integer datatype
46. ARRAY
Program to find sum of array elements
import array
sum=0
a=array.array('i',[1,2,3,4])
for i in a:
sum=sum+i
print(sum)
Result:
10
47. Convert LIST into ARRAY
īfromlist() function is used to append list to array.
īList is act like a array.
Syntax:
arrayname.fromlist(list_name)
Example
import array
sum=0
l=[6,7,8,9]
a=array.array('i',[])
a.fromlist(l)
for i in a:
sum=sum+i
print(sum)
Result:
35
48. Methods in ARRAY
a=[2,3,4,5]
syntax:
array(data type, value list)
array(i, [2,3,4,5])
Syntax Example
append()
>>>a.append(6)
[2,3,4,5,6]
insert(index, element)
>>>a.insert(2,10)
[2,3,10,5,6]
pop(index)
>>>a.pop(1)
[2,10,5,6]
count() a.count()
4
reverse() >>>a.reverse()
[6,5,10,2]
49. Assignment
1.Square root using newtons method
2.GCD of two numbers
3.Exponent of number
4.Sum of array elements
5.Linear search
6.Binary search