1664611760basics-of-python-for begainer1 (3).pptx

krsonupandey92 25 views 74 slides Jul 23, 2024
Slide 1
Slide 1 of 74
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74

About This Presentation

basics of python


Slide Content

A warm welcome to Careerera family

Introduction to Programming using Python ‹#›

WHAT IS PYTHON https://www.careerera.com ‹#› 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.

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 P rogramming Language

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

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. 

‹#› 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” STRINGS DATATYPES

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

‹#› 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 :- SUBSET IN PYTHON

‹#› 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) USES OF POSITION

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.

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 .

For example : HELLO WORLD PROGRAM IN PYTHON HELLO WORLD PROGRAM IN PYTHON For example : ‹#›

  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  J upyter notebook and the program will instantiate a local server at localhost:8888 

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.

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

‹#› 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 . TUPLE IN PYTHON

SYNTAX AND EXAMPLES OF TUPLES ‹#› Syntax: a=(1,5,8,9) B=(True , False , True) Tuple Example:

‹#› 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. SET IN PYTHON

SYNTAX AND EXAMPLES OF SETS ‹#› Syntax: a={“Apple” , “Orange” , “Banana” } Set Example:

‹#› 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{}.  DICTIONARIES IN PYTHON

SYNTAX AND EXAMPLES OF DICTIONARIES ‹#› Syntax: a={“keys “ :”values”, “keys “ :”values”} D ictionary Example :

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.

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 : Addition Subtraction Multiplication Division Modulus Exponentiation Floor division

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

‹#› 2 . Subtraction Operator :  In Python, ( –  )is the subtraction operator. It is used to subtract the second value from the first value. Example : SUBTRACTION OPERATORS

‹#› 3. Multiplication Operator :  In Python,  *  is the multiplication operator. It is used to find the product of 2 values. Example : MULTIPLICATION OPERATORS

‹#› 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 : DIVISION 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 : MODULUS OPERATOR

‹#› 6.Exponentiation O perator :  In Python,  **  is the exponentiation operator. It is used to raise the first operand to power of second. Example : EXPONENTIATION OPERATOR

‹#› 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 : FLOOR DIVISION

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.

‹#› Operator Description Example and  Returns True if both statements are true x < 5 and  x < 10 or Returns True if one of the statements is true x < 5 or x < 4 not Reverse the result, returns False if the result is true not(x < 5 and x < 10) TYPES OF LOGICAL OPERATORS

CONDITIONAL STATEMENT https://www.careerera.com ‹#› 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

‹#› S yntax is: if(condition):   

IF STATEMENT ‹#›   If statement is most usually used as a conditional statement.  

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.

‹#› If-else program: PROGRAMS FOR IF-ELSE

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 :

‹#› 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: NESTED CONDITION

‹#› 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: LOOPS IN PYTHON

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:

PROGRAMS FOR LOOPS ‹#› Loop program: While loop program:

‹#› With the  while  loop we can execute a set of statements as long as a condition is true. For Example: WHILE LOOP IN PYTHON

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.

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.

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 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: Class Definition Syntax: class ClassName: # Statement-1 . . . # Statement-N

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.

TYPES OF INHERITANCE ‹#›

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 .

‹#› 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:

‹#› 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) PROGRAM ON FILTER FUNCTION

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.

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)   

‹#› 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) PROGRAM ON REDUCE FUNCTION

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:

‹#› The  max()  function returns the item with the highest value, or the item with MAX FUNCTION IN PYTHON

‹#› The  sort()  method sorts the list ascending by default. For Example: SORT FUNCTION IN PYTHON

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.

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.

‹#› For example: PROGRAM SHOWING THE USE OF METHODS

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. De fault arguments : default arguments are values that are provided while defining functions. 2. K eyword arguments : Functions can also be called using keyword arguments , But all the keyword arguments should match the parameters in the function definition. 3. P ositional arguments : During function call, values passed through arguments should be in the order of parameters in the function definition. This is called  positional arguments.

WORKING WITH FUNCTIONS WITH AND WITHOUT ARGUMENTS ‹#› Program without arguments:

‹#› PROGRAM WITH ARGUMENTS:

LOGIC FLOWCHARTS (Intuitive understanding of code flow) ‹#› A  flowchart  typically shows the  flow  of data in a process, It provides a pic torial representation of the algorithm detailing the steps more clearly , thus flow charts are easily understandable.

DIAGRAMATICAL REPRESENTATION OF A FLOW CHART ‹#›

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.

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:

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 L oops in Python is used to iterate over a sequence ( list ,  tuple ,  string ) or other iterable objects. Iterating over a sequence is called traversal.

PRACTICE LIST COMPREHENSIONS ‹#› List Comprehensions is a very powerful tool, which creates a new list based on another list, in a single, readable line.

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]

Thank You !!! ‹#› (USA) 2-Industrial Park Drive, E-Waldorf, MD, 20602, United States (USA) +1-844-889-4054 (Singapore) 3 Temasek Avenue, Singapore 039190 [email protected] www.careerera.com (INDIA) B-44, Sector-59, Noida Uttar Pradesh 201301 (INDIA) +91-92-5000-4000
Tags