Sei sulla pagina 1di 13

PYTHON

SUBMITTED BY:
AKASH(17001003006)
WHAT IS PYTHON?

 Python is a high-level programming language.


 It is a general purpose and powerful
programming language.
 It is an open source programming language.
 It is extensively used in web applications ,
machine learning, AI.
 Developed by Guido van Rossum, a Dutch
Scientist.
FEATURES OF PYTHON
WHERE DO WE USE PYTHON?
 Web Application in Python:
 We can use Python to create web applications on many levels of
complexity.
 There are many excellent Python frameworks like Django ,
Flask for this purpose
 DATA ANALYSIS IN PYTHON:
 Data Analysis is about making predictions with data
 It has grown in popularity due to it’s excellent libraries like
NumPy , Pandas etc.
 Machine Learning In Python:
 Python has many wonderful libraries to implement
ML algorithm like SciKit-Learn , Tensorflow
 It is heavily used in Face recognition, medical data, marketing
etc
BASIC PROGRAMS

>>> print(“hello world”)


 Output: hello world
 ADDING TWO NUMBERS :
>>> a = 10
>>> b = 20
>>>a+b
>>>30
DATA TYPES IN PYTHON

Text Type: str


Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type : dictionary
Set Types: set
Boolean Type: bool
STRING : LIST : TUPLES
 STRING:
 String is a data type used in programming.
 It is used to represent characters rather than numbers.
 EXAMPLE: “python language”
 LIST:
 List is a Data type available in Python which can written as a list of
common-separated values between square brackets.
 EXAMPLE: List = [1, 2, ”Akash”, ”ECE”] , List1 = [5, 7, 8, 8.5].
 TUPLES:
 Tuples is a sequence of immutable Python objects.
 Tuples are represented with parenthesis.
 Tuple = (1,8,5,4)
 Tuple1=(“akash” , ”cool”)
METHODS
 METHODS ON LIST:
 APPEND : append object at the end
for example: a=[‘a’,’b’]
a.append(123) >>> output : [‘a’, ’b’, 123]
 EXTEND : Extend a list with the objects from an iterable
For example: a=[‘a’,’b’]
a.extend([1,2,3]) >>> Output : [‘a’, ’b’, 1, 2, 3]
 INSERT : Insert an object into a list (index,element).
For example: a= [‘a’, ’b’, 1, 2, 3]
a.insert(3, 4.4) >>> Output : [‘a’, ’b’, 1, 4.4, 2, 3]
 REMOVE : Removes an object from a list (element).
For example: a= [‘a’, ’b’, 1, 4.4, 2, 3]
a.remove(4.4) >>> Output : [‘a’, ’b’, 1, 2, 3]
 POP : Remove element from a list(index).
For example: a= [‘a’, ’b’, 1, 2, 3]
a.pop() >>> Output : [‘a’, ’b’, 1, 2]
TUPLE METHODS
 COUNT : returns the number of times a specified value appears in the
tuple
 For Example:
>>>tuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
>>>x = tuple.count(5)
>>>print(x)
 >>> 2
 INDEX : returns the first occurrence of the specified value
For Example:
tuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = tuple.index(8)
print(x)
>>> 3
EXCEPTION HANDLING

 TRY: Test a block of code for errors.


 EXCEPT: This block handle the error.
 FINALLY:This block execute the code,regardless of the result of the
try- and except blocks.
 For Example:
try:
print(x)

except:
print("Something went wrong")

finally:
print("The 'try except' is finished")

else:print(“nothing went wrong”)


FUNCTIONS
 A function is a block of code which only runs when it is called.
 We can pass data, known as parameter, into a function.
 A function can return data as a result.
 In Python we use def keyword :
EXAMPLE:
def my_function():
print(“my first function”)
my_function()
DEFAULT PARAMTER VALUE:
EXAMPLE:
def my_function(country = “India"):
print("I am from " + country)
my_function(“Canda")
my_function(“US")
my_function()
my_function("Brazil")
CLASSES AND OBJECTS
 A Class is like an object constructor, or a "blueprint" for creating
objects.
 To create a class we use keyword class :
 FOR EXAMPLE:
 class Person:
def __init__(self, name, age):
self.name = name
self.age = age

def myfunc(self):
print("Hello my name is " + abc.name)

p1 = Person(“Akash", 19)
p1.myfunc()
THANKU

Potrebbero piacerti anche