0% found this document useful (0 votes)
18 views

1664611760basics-of-python-1

Uploaded by

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

1664611760basics-of-python-1

Uploaded by

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

®

CAREERERA
A warm welcome to Careerera family
®

CAREERERA

Introduction to Programming using Python

2
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.

https://www.careerera.com 3
WHY PYTHON IS WIDELY USE?
• The python language is one of the most accessible programming
languages
• Due to its ease of learning and usage, python codes can be easily
written and executed much faster than other programming
languages.
• Python works on different platforms (Windows, Mac, Linux etc).
• Python has a simple syntax.
• Python is easy to code.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written.
• Python is a object Oriented Programming Language
4
DATA TYPES -NUMBERS

• Number data types store numeric values. They are immutable data
types, means that changing the value of a number data type results
in a newly allocated object.
• Number objects are created when you assign a value to them.

For example :−
var1 = 10
var2 = 30

5
BOOLEAN

• Python boolean type is one of the built-in data types provided by


Python, which are defined by the True or False keywords.
• The bool() method is used to return or convert a value to
a Boolean value i.e., True or False, using the standard truth testing
procedure.

6
STRINGS DATATYPES

• Strings are arrays of bytes representing Unicode characters.


However, Python does not have a character data type, a single
character is simply a string with a length of 1. Square brackets
can be used to access elements of the string. individual
characters of a String can be accessed by using the method of
Indexing.

For Example:-
value = “Careerera”

7
CONCATENATION IN PYTHON

Concatenating means obtaining a new string that


contains both of the original strings. You can use “+”
operator to concatenate strings in python.
For Example:-

8
SUBSET IN PYTHON

Subset - A set of which all the elements are contained in


another set.
• The issubset() method returns True if all elements of a set
are present in another set (passed as an argument).
• If not, it returns False.
• For Example :-

9
USES OF POSITION

Position: The index() method returns the index position


of the first occurance of the specified item.
Raises a ValueError if there is no item found.

For Example:
Syntax:
list.index(element, start, end)

10
VARIABLES

• Variables are reserved memory locations to store values. This


means that when you create a variable you reserve some
space in memory.
• Based on the data type of a variable, the interpreter allocates
memory and decides what can be stored in the reserved
memory.
• Therefore, by assigning different data types to variables, you
can store integers, decimals or characters in these variables.

11
BASIC PROGRAMMING SYNTAX
• Python syntax are very much simple and easy.
• Every programming language has its own set of rules that make
up its basic syntax.
• Hence ,it’s easy to code in Python.
• For Example:
print(“ Learn from Careerera “)
The syntax mention above is the basic syntax of python
programming language to print .

12
For example :

HELLO WORLD PROGRAM IN PYTHON

HELLO WORLD PROGRAM IN PYTHON

For example :

13
INTEGRATED DEVELOPMENT ENVIRONMENT(IDE) FOR PYTHON

• Jupyter IDE can be use for python coding.


• Jupyter is a free, open-source, interactive web tool that allows
editing and running files via a web browser.
• To launch a Jupyter notebook, open your terminal and navigate to
the directory where you would like to save your notebook.
• Then type the command Jupyter notebook and the program will
instantiate a local server at localhost:8888

14
DATA STRUCTURE

• Data structures are “containers” that organize and


group data according to type.
• The basic Python data structures in Python include
• list, array, tuples, and dictionary.
• Each of the data structures is unique in its own way.
LIST IN PYTHON​

• Lists are used to store multiple items in a single variable.


• List items are ordered, changeable, and allow duplicate values.
• The elements in a list are indexed according to a definite sequence .
• Indexing starts from 0,1,2,3 so on..
• items in a list need not be of the same type.

16
SYNTAX AND EXAMPLES OF LIST
Syntax:
Li=[] # empty list
Li1=[1,2,34,5] # list containing element’s
List Example:

17
TUPLE IN PYTHON

• A tuple is a collection of objects which is ordered and immutable.


• Tuples are ordered, it means that the items have a defined order,
and that order will not change.
• Tuples are written with round brackets.
• tuples allow duplicate values.
• Tuples items can be indexed .

18
SYNTAX AND EXAMPLES OF TUPLES

• Syntax:
• a=(1,5,8,9)
• B=(True , False , True)
• Tuple Example:

19
SET IN PYTHON

• Sets are used to store multiple items in a single variable.


• A set is a collection which is unordered
• Unordered means that the items in a set do not have a defined
order.
• Sets are unchangeable, meaning that we cannot change the
items after the set has been created.
• Sets are unindexed
• Sets are written with curly brackets.

20
SYNTAX AND EXAMPLES OF SETS

Syntax:
• a={“Apple” , “Orange” , “Banana” }
Set Example:

21
DICTIONARIES IN PYTHON

• Dictionaries are used to store data values in key:value pairs.


• A dictionary is a collection which is ordered*, changeable and does
not allow duplicates.
• Dictionary holds a pair of values
• Dictionary can also be created by the built-in function dict().
• An empty dictionary can be created by just placing to curly braces{}.

22
SYNTAX AND EXAMPLES OF DICTIONARIES

Syntax:
• a={“keys “ :”values”, “keys “ :”values”}
Dictionary Example:

23
OPERATORS

• Operators are used to perform operations on values and


variables in Python.
• These are standard symbols used for the purpose of logical and
arithmetic operations.
• The value that the operator operates on is called the operand.

24
TYPES OF ARITHMETIC OPERATORS
• Arithmetic operators are used to perform mathematical operations like
addition, subtraction, multiplication and division.
There are 7 arithmetic operators in Python :
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
6. Exponentiation
7. Floor division

25
ADDITION OPERATORS
1. Addition Operator : In Python, + is the addition
operator. It is used to add 2 values.
Example :

26
SUBTRACTION OPERATORS

2 . Subtraction Operator : In Python, (– )is the subtraction


operator. It is used to subtract the second value from the
first value.
Example :

27
MULTIPLICATION OPERATORS

3. Multiplication Operator : In Python, * is the multiplication


operator. It is used to find the product of 2 values.
Example :

28
DIVISION OPERATOR

4. Division Operator : In Python, / is the division operator. It


is used to find the quotient when first operand is divided by
the second.
Example :

29
MODULUS OPERATOR

• 5. Modulus Operator : In Python, % is the modulus


operator. It is used to find the remainder when first
operand is divided by the second.
Example :

30
EXPONENTIATION OPERATOR

6.Exponentiation Operator : In Python, ** is the


exponentiation operator. It is used to raise the first
operand to power of second.
Example :

31
FLOOR DIVISION
• 7. Floor division : In Python, // is used to conduct the floor
division. It is used to find the floor of the quotient when first
operand is divided by the second.
Example :

32
LOGICAL OPERATOR
• Logical Operators in Python are used to perform logical
operations on the values of variables.
• The value is either true or false. We can figure out the conditions
by the result of the truth values.
• There are mainly three types of logical operators in
python : logical AND, logical OR and logical NOT.

33
TYPES OF LOGICAL OPERATORS

Operator Description Example


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

or Returns True if one of the x < 5 or x < 4


statements is true

not Reverse the result, not(x < 5 and x <


returns False if the result 10)
is true

34
CONDITIONAL STATEMENT

Conditional statements are also called decision-making statements.


We use those statements while we want to execute a block of code
when the given condition is true or false.

Type of condition statement in Python:


If statement.
If Else statement.
Elif statement.
Nested condition

https://www.careerera.com 35
Syntax is:
if(condition):

36
IF STATEMENT
• If statement is most usually used as a conditional statement.

37
IF ELSE STATEMENT IN PYTHON

• The if…else statement in Python is used for decision making.


• The block of lines indented the same amount after the colon (:) will be executed whenever the condition is TRUE.

38
PROGRAMS FOR IF-ELSE

• If-else program:

39
ELIF STATEMENT

• Elif is a shortcut of else if condition statements. In Python


one or more conditions are used in the elif statement
For Example :

40
NESTED CONDITION

• Nested if statements means an if statement inside


another if statement.
• When a program selects one of many paths, it can use nested or
chained conditions.
For Example:

41
LOOPS IN PYTHON

• A loop is used for iterating over a sequence (that is either a list, a


tuple, a dictionary, a set, or a string).
• With the for loop we can execute a set of statements, once for each
item in a list, tuple, set etc.
For Example:

42
INTRO​TO FOR LOOPS IN PYTHON​
• A for loop is used for iterating over a sequence (that is
either a list, a tuple, a dictionary, a set, or a string).
• With the for loop we can execute a set of statements,
once for each item in a list, tuple, set etc.
For Example:

43
PROGRAMS FOR LOOPS

• Loop program:

• While loop program:

44
WHILE LOOP IN PYTHON

• With the while loop we can execute a set of statements


as long as a condition is true.

For Example:

45
Basic Concepts of Object-Oriented
Programming In Python

• Object-Oriented Programming(OOP), is all about creating “objects”.


• The concept of OOP in Python focuses on creating reusable code.
• Major Python OOPs concept-
• Class.
• Object.
• Inheritance.
• Encapsulation.

46
Class

• A class is a blueprint for the object.


• It is a logical entity that has some specific attributes and
methods.
• The example for class of parrot can be :
class Parrot:
pass
• The class keyword is use to define an empty class Parrot.
• From class, we construct instances. An instance is a
specific object created from a particular class.
47
Class Definition Syntax: class ClassName: # Statement-1 . . . # Statement-N

Object

• The object is an entity that has state and behavior.


• The object is an entity that has state and behavior.
• When we define a class, it needs to create an object to
allocate the memory.
• Class Definition Syntax:
class ClassName:
# Statement-1
……
# Statement-N
48
Class Definition Syntax: class ClassName: # Statement-1 . . . # Statement-N

ENCAPSULATION

• we can restrict access to methods and variables that prevents


data from direct modification which is called encapsulation.
• In encapsulation code and data are wrapped together within
a single unit .
• Encapsulation prevents your code from unauthorized user’s.
• For example:

49
INHERITANCE

• Inheritance is the most important aspect of object-oriented


programming, which simulates the real-world concept of inheritance.
• It specifies that the child object acquires all the properties and
behaviors of the parent object.
• By using inheritance, we can create a class which uses all the
properties and behavior of another class.

50
TYPES OF INHERITANCE

51
FUNCTIONS

• A function is a block of code which only runs when it is called.


• The idea is to put some commonly or repeatedly done task together
and make a function so that instead of writing the same code again
and again for different inputs, we can call the function to reuse code
contained in it over and over again.

52
USES OF LENGTH FUNCTION

Length : len() function is an inbuilt function in Python


programming language that returns the length of the string.
Syntax:
len(string)
For Example:

53
PROGRAM ON FILTER FUNCTION

• The filter() method constructs an iterator from elements of an


iterable for which a function returns true.
• Python's filter() is a built-in function.
• The filter function takes in two arguments

SYNTAX:
filter(function, iterable)

54
UNDERSTANDING LAMBDA FUNCTIONS

• A lambda function is a small, anonymous function


that take any number of arguments but only have one expression.
• We create them with the lambda keyword instead of the
traditional def keyword.
55
OVERVIEW OF MAP FUNCTIONS

• Map is a function that takes as an input a collection


Example:
• a list [‘BBA’,’MBA’,’BCA’], and a function e.g. upper().
• Then it will move every element of the collection through this function
and produce a new collection with the same count of elements.

SYNTAX:
map(function, iterables)

56
PROGRAM ON REDUCE FUNCTION
• The reduce() function, as the name describes, applies a given
function to the iterables and returns a single value.
• The reduce() function is defined in the functools module.
• The reduce function can take in three arguments, two of which are
required.
reduce(function, iterable [, initializer])
SYNTAX:
reduce(function, iterables)

57
EXPLORING COMMONLY USED BUILT IN FUNCTIONS

• The min() function returns the item with the lowest value, or the
item with the lowest value in an iterable.

For Example:

58
MAX FUNCTION IN PYTHON

The max() function returns the item with the highest


value, or the item with

59
SORT FUNCTION IN PYTHON

• The sort() method sorts the list ascending by default.


For Example:

60
PROGRAMS USING USER DEFINED FUNCTIONS
• A user-defined function (UDF) is a function provided by the user of
a program or environment.
For Example:
Here sum is the user define function.

61
Methods

• A method in python is somewhat similar to a function, except it is


associated with object/classes.
• Method is called by its name, but it is associated to an
object (dependent).
• A method is implicitly passed the object on which it is invoked.

62
PROGRAM SHOWING THE USE OF METHODS
• For example:

63
ARGUMENT’S

• An argument is the value that are sent to the function when it is


called.
• Types of Arguments in Python Function Definition:
1.Default arguments :default arguments are values that are
provided while defining functions.
2.Keyword arguments: Functions can also be called using keyword
arguments , But all the keyword arguments should match the
parameters in the function definition.
3.Positional arguments: During function call, values passed through
arguments should be in the order of parameters in the function
definition. This is called positional arguments.

64
WORKING WITH FUNCTIONS WITH AND WITHOUT ARGUMENTS

Program without arguments:

65
PROGRAM WITH ARGUMENTS:

66
LOGIC FLOWCHARTS
(Intuitive understanding of code flow)

• A flowchart typically shows the flow of data in a process,


• It provides a pictorial representation of the algorithm
detailing the steps more clearly , thus flow charts are easily
understandable.

67
DIAGRAMATICAL REPRESENTATION OF A FLOW CHART

68
PSEUDOCODE
• Pseudocode is a method of planning which enables the
programmer to plan without considering about the
syntax.
• It has no syntax like any of the programming language
and thus can’t be compiled or interpreted by the
computer.

69
LIST COMPREHENSION​
• List comprehension offers a shorter syntax when you want to
create a new list based on the values of an existing list.
For Example:

70
USE CASES VS LOOPS

• A use case is a methodology used in system analysis to identify,


clarify and organize system requirements.
• It also defines a list of steps that illustrate how a process will be
carried out in a system.
• While Loops in Python is used to iterate over a sequence (list, tuple,
string) or other iterable objects.
• Iterating over a sequence is called traversal.

71
PRACTICE LIST COMPREHENSIONS

• List Comprehensions is a very powerful tool, which creates a new list


based on another list, in a single, readable line.

72
FUNCTIONS WITH RETURN ITEMS

• A return statement is used to end the execution of the function call


and “returns” the result (value of the expression following the
return keyword) to the caller.
The statements after the return statements are not executed.
Syntax:

def fun():
statements
return [expression]

73
Thank You !!!
(USA)
(INDIA)
2-Industrial Park Drive, E-Waldorf, MD,
20602, B-44, Sector-59, Noida
United States Uttar Pradesh 201301

(INDIA)
(USA) +91-92-5000-4000
+1-844-889-4054

(Singapore)
3 Temasek Avenue, Singapore 039190
[email protected]
www.careerera.com

74

You might also like