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

Basics of Python

The document provides an introduction to programming using Python, covering its history, syntax, variables, operators, data types, and basic programming concepts. It explains key features such as object-oriented programming, functions, and data structures, along with examples of how to use various operators and control structures. Additionally, it discusses integrated development environments and built-in functions in Python.

Uploaded by

10321210130
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Basics of Python

The document provides an introduction to programming using Python, covering its history, syntax, variables, operators, data types, and basic programming concepts. It explains key features such as object-oriented programming, functions, and data structures, along with examples of how to use various operators and control structures. Additionally, it discusses integrated development environments and built-in functions in Python.

Uploaded by

10321210130
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

CAREERERA

Introduction to Programming using Python

1
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 2
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
3
WHAT ARE THE 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 .

4
HOW TO PERFORME HELLO WORLD PROGRAM IN PYTHON?

• For example :

https://www.careerera.com 5
WHAT ARE 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.

6
WHAT ARE 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.

7
HOW MANY TYPES OF OPERATORS ?
There are 7 arithmetic operators in Python :
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators

https://www.careerera.com 8
HOW MANY TYPES OF ARITHMETIC OPERATORS ?
There are 7 arithmetic operators in Python :
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
6. Exponentiation
7. Floor division

9
HOW ADDITION OPERATOR IS USED ?

1. Addition Operator : In Python, + is the addition


operator. It is used to add 2 values.
Example :

10
HOW SUBTRACTION OPERATOR IS USED ?

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


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

11
HOW MULTIPLICATION OPERATOR IS USED?

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


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

12
HOW DIVISION OPERATOR IS USED ?
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 :

13
HOW MODULUS OPERATOR IS USED ?
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 :

14
WHAT IS EXPONENTIATION OPERATOR ?

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


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

15
HOW ARE USED 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 :

16
WHAT ARE 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.

17
HOW MANY 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, returns not(x < 5 and x < 10)
False if the result is true

18
WHAT ARE 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

19
WHAT IS 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.

20
WHAT ARE 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”

21
WHAT IS 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:-

22
WHAT ARE 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 :-

23
WHAT IS 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)

24
WHAT ARE 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

25
WHAT ARE DATA STRUCTURES ?

• Data structures are “containers” that organize and


group data according to type.
• The basic Python data structures in Python include:-
list, set, tuples, and dictionary.
• Each of the data structures is unique in its own way.
WHAT IS 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.

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

28
WHAT IS 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 .

29
WHAT IS SYNTAX AND EXAMPLE OF TUPLES ?

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

30
WHAT IS SETS 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.

31
WHAT IS SYNTAX AND EXAMPLE OF SETS ?

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

32
WHAT IS 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{}.

33
WHAT IS SYNTAX AND EXAMPLE OF DICTIONARIES ?

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

34
WHAT ARE 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
HOW THE IF (CONDITION) FLOW CHART LOOKS LIKE?

https://www.careerera.com 36
HOW TO USE IF STATEMENT ?
• If statement is most usually used as a conditional statement.

37
HOW TO USE 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.

https://www.careerera.com 38
HOW TO USE 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 :

39
WHAT ARE 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:

40
WHAT ARE 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:

41
WHAT IS FOR LOOP 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:

42
HOW TO WRITE PROGRAMS FOR FOR LOOP & WHILE LOOP IN PYTHON?

• Loop program:

• While loop program:

43
HOW WHILE LOOP IS USED IN PYTHON ?
• With the while loop we can execute a set of statements
as long as a condition is true.

For Example:

44
WHAT ARE THE 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.

45
WHAT ARE 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.

46
HOW TO USE 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:

47
WHAT IS 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)

48
WHAT IS LAMBDA FUNCTION?
• 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.

https://www.careerera.com 49
WHAT IS MAP FUNCTION ?
• 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)

https://www.careerera.com 50
WHAT IS 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)

51
WHAT KIND OF BUILT IN FUNCTION IN PYTHON?
• The min() function returns the item with the lowest value,
or the item with the lowest value in an iterable.

For Example:

https://www.careerera.com 52
WHAT IS MAX FUNCTION IN PYTHON ?

The max() function returns the item with the highest


value, or the item with

53
HOW SORT FUNCTION IS USED IN PYTHON ?

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


For Example:

54
WHAT IS 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.

https://www.careerera.com 55
WHAT IS 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.
56
Class Definition Syntax: class ClassName: # Statement-1 . . . # Statement-N

WHAT IS 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
57
WHAT IS 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.

58
HOW MANY TYPES OF INHERITANCE IN PYTHON?

59
Class Definition Syntax: class ClassName: # Statement-1 . . . # Statement-N

WHAT IS 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:

60
WHAT ARE 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.

61
HOW TO USE METHODS ? GIVE EXAMPLE.

• For example:

62
WHAT ARE ARGUMENT’S IN PYTHON?

• 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.
https://www.careerera.com 63
HOW TO WORK WITH FUNCTIONS WITH AND WITHOUT ARGUMENTS ?

Program without arguments:

64
HOW TO USE WITH ARGUMENTS?

65
WHAT ARE 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.

66
WHAT IS DIAGRAMATICAL REPRESENTATION OF A FLOW CHART ?

67
WHAT IS 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.

68
WHAT IS 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:

69
HOW USE CASE VS LOOPS WORK ?

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

70
HOW FUNCTIONS WORKS 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]

71
Thank You

https://www.careerera.com 72

You might also like