1
Learn . Practice . Upskil at Ybi Foundation
                             Introduction to Python
                                                                   Master 4.0
    Study Material   www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
2
    HISTORY                                    Learn . Practice . Upskil at Ybi Foundation
    Python was created by Guido van Rossum, and first released on February 20, 1991
    as Python 0.9.0.
    While you may know the python as a large snake, the name of the Python
    programming language comes from an old BBC television comedy sketch series
    called Monty Python’s Flying Circus.
    Guido van Rossum began working on Python in the late 1980s as a successor to
    the ABC programming language.
    Python 2.0 was released in 2000. Python 3.0 released in 2008, was a major
    revision not completely backward-compatible with earlier versions. Python latest
    version 3.11.2 released on Feb 8, 2023.
    Python consistently ranks as one of the most popular programming languages.
    Study Material   www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
3
    PYTHON                                      Learn . Practice . Upskil at Ybi Foundation
    Python is a general purpose, open source, high-level programming language and
    also provides number of libraries and frameworks. Python has gained popularity
    because of its simplicity, easy syntax and user-friendly environment.
    Python is strongly typed (i.e. types are enforced), dynamically, implicitly typed (i.e.
    you don’t have to declare variables), case sensitive (i.e. ybi and YBI are two
    different variables) and object-oriented (i.e. everything is an object).
     Study Material   www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
4
    REASONS THAT MAKE      PYTHON
                  Learn . Practice . Upskil atGREAT       FOR LEARNING
                                               Ybi Foundation
    •         It is easy to learn – the time needed to learn Python is shorter than for many other languages;
              this means that it’s possible to start the actual programming faster
    •         It is easy to use for writing new software – it’s often possible to write code faster when using
              Python
    •         It’s open source, is easy to obtain, install and deploy – Python is free, open and multiplatform;
              not all languages can boast that.
    •         Some languages require you to modify code to run on different platforms, but Python is a
              cross-platform language, which means you can run the same code on any operating system
              with a Python interpreter.
    •         It’s extendable. Python code can be written in other languages (such as C++), and users can
              add low-level modules to the Python interpreter to customize and optimize their tools.
    •         It has a multiple standard library. This library is available for anyone to access and users don’t
              have to write code for every single function—they can access built-in modules that help with
              issues in everyday programming and more.
        Study Material   www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
5
    USAGE OF PYTHON
               Learn . Practice . Upskil at Ybi Foundation
    •   Desktop Applications
    •   Web Applications
    •   Data Science
    •   Artificial Intelligence
    •   Machine Learning
    •   Scientific Computing
    •   Robotics
    •   Internet of Things (IoT)
    •   Gaming
    •   Mobile Apps
    •   Data Analysis and Pre-processing
              www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
6
    COMPANIES USING
               Learn . PracticePYTHON
                               . Upskil at Ybi Foundation
    •   Google (Components of Google spider and Search Engine)
    •   Yahoo (Maps)
    •   YouTube
    •   Mozilla
    •   Dropbox
    •   Microsoft
    •   Cisco
    •   Spotify
             www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
7                                                                                                         August 28, 2023
                              Learn . Practice . Upskil at Ybi Foundation
    Introduction Google Colab
                                  https://colab.research.google.com/
    www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
8                                                                                                                  August 28, 2023
    GOOGLE COLAB
              Learn . Practice . Upskil at Ybi Foundation
    •   Google Colab is an online representation of Jupyter Notebook.
    •   While Jupyter Notebook needs installation on a computer and can uses local machine
        resources, Colab is a full-fledged cloud solution for Python coding.
    •   Google Colab allows anybody to write and execute python code through the browser on
        laptop or mobile.
    •   You can write Python codes using Colab on your Google Chrome or Mozilla Firefox or any
        other web browser.
             www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
9                                                                                                                  August 28, 2023
    HOW TO OPENLearnGOOGLE               COLAB
                     . Practice . Upskil at Ybi Foundation
    •   Step 1: Open any browser
    •   Step 2: Login to your Google account
    •   Step 3: Search for Colab in google search
    •   Step 4: Click or open URL ' https://colab.research.google.com/ '
    •   Step 5: Click on New Notebook option in bottom right of pop up or from File
        menu
             www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
10                                                                                                                 August 28, 2023
     How to CreateLearn
                   New          Notebook
                        . Practice . Upskil at Ybi Foundation
             www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
11                                                                                                                       August 28, 2023
     GOOGLE COLAB
               Learn .LAYOUT
                      Practice . Upskil at Ybi Foundation
                                                                          1.Rename File
                                                                          2.Menu
                                                                          3.Table of content
                                                                          4. Add code & text cells
                                                                          5.Share file or add comments
                                                                          6.Connect
                                                                          7.Move cells up & down, add comments, delete cell
                                                                          8.Text cell
                                                                          9.Code cell
            www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
                                   Learn . Practice . Upskil at Ybi Foundation
                               Python Variables
A Python variable is a symbolic name that is a reference or pointer to an object. Once an object
  is assigned to a variable, you can refer to the object by that name. But the data itself is still
                                   contained within the object.
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
WHAT IS A VARIABLE
              Learn . Practice . Upskil at Ybi Foundation
A variable is any characteristic, number, or quantity that can be
measured or counted.
•Age (17, 25, 42, ...)
•Gender (male, female)
•Income (₹ 20000, ₹ 35000, ₹ 45000, ...)
•House price (₹ 350000, ₹ 570000, ...)
•Country of birth (India, Russia, USA, ...)
•Eye colour (brown, green, blue, ...)
•Vehicle make (TATA, Maruti, ...)
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
VARIABLES                       Learn . Practice . Upskil at Ybi Foundation
• A variable is used to store information that can be
  referenced later.
• We can assign data and outputs to a variable and can create
  an unlimited number of variables, but we have to make sure
  to give each variable a unique name.
      www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
DEFINE A VARIABLE
              Learn . Practice . Upskil at Ybi Foundation
Variables are used to store information and represent your data input.
                                                                 We defined a variable x that is equal to the
                                                                 value of 5 and then ask the computer to tell the
                                                                 value of that variable.
                                                                 Type x equals 5, i.e. write x and then execute
                                                                 the cell, and we get the output: 5.
                                                                 We assigned to y a value 8 and use the print()
                                                                 function as print(y), the machine will simply
                                                                 execute this command and provide the output
                                                                 as value of y.
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
STRINGS                       Learn . Practice . Upskil at Ybi Foundation
                                                          Type single or double quotation
                                                          marks around the        name Ybi
                                                          Foundation. Python displays ‘Ybi
                                                          Foundation’ if you don’t use the
                                                          print() function. Should you use
                                                          print(), the output will be shown
                                                          with no quotes – you’ll be able to
                                                          see plain text.
    www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
VARIABLE NAMING
             Learn . RULES
                     Practice . Upskil at Ybi Foundation
Python allows Names to be a combination of
• lowercase letters (a to z) or
• uppercase letters (A to Z) or
• digits (0 to 9) or
• an underscore (_).
Names are case sensitive and cannot start with a number.
Names in Python cannot use any special symbols like !, @, #, $, % etc.
They can contain letters, numbers, and underscores.
ybi YBi _ybi _2_ybi_ ybi_2 YbI
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
Allowed VariableLearn
                 Names. Practice . Upskil at Ybi Foundation
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
Not Allowed Variable      Names
                Learn . Practice . Upskil at Ybi Foundation
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
Reserved Key Words     for Variable
              Learn . Practice                    Names
                               . Upskil at Ybi Foundation
• Reserved words (also called keywords) are defined with
  predefined meaning and syntax in the language.
• These keywords have to be used to develop programming
  instructions.
• Reserved words can’t be used as identifiers for other
  programming elements like name of variable, function etc.
        www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
Reserved Key Words     for Variable
              Learn . Practice                    Names
                               . Upskil at Ybi Foundation
['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async',
'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda',
'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
SYNTAX                          Learn . Practice . Upskil at Ybi Foundation
• Python has no mandatory statement termination characters
  and blocks are specified by indentation.
• Indent to begin a block, dedent to end one.
• Statements that expect an indentation level end in a colon
  (:).
      www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
ADD COMMENTSLearn . Practice . Upskil at Ybi Foundation
                                                                  •     Comments      are sentences  not
                                                                        executed by the      programming
                                                                        language i.e. not read them as
                                                                        instructions.
                                                                  •     Put a hash sign (#) at the beginning of
                                                                        each line to work as a comment.
                                                                  •     For comments on two or more lines,
                                                                        place the hash sign at the beginning
                                                                        of each line.
                                                                  •     Comments start with the pound (#)
                                                                        sign and are single-line, multi-line
                                                                        strings are used for multi-line
                                                                        comments.
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
LINE CONTINUATION
             Learn . Practice . Upskil at Ybi Foundation
                                                           • To write code in multiple
                                                             lines, so that program read it
                                                             as one command.
                                                           • This could be achieved by
                                                             putting a back slash (\) at the
                                                             end of the first line. It
                                                             indicates the continuation of
                                                             the same code on a new line.
        www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
INDEXING                        Learn . Practice . Upskil at Ybi Foundation
Python is a zero index language
                                                     Use square brackets and specify the
                                                     position/index of the letter to extract.
                                                    Y     b     i         F     o     u      n     d     a    t    i    o    n
                                                    0     1     2    3    4     5      6     7     8     9    10   11   12   13
                                                     -     -    -     -    -
                                                                                -9    -8    -7    -6     -5   -4   -3   -2   -1
                                                    14    13   12    11   10
      www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org    Click to Join Live Doubt Session
STRUCTURE YOUR
            Learn .CODE        WITH
                   Practice . Upskil         INDENTATION
                                     at Ybi Foundation
                                             •   Indentation is important as it will define the hierarchy of
                                                 codes for execution in python.
                                             •   In the example code, def and return clearly in
                                                 distinguishable blocks of code or blocks of
                                                 commands.
                                             •   Everything that belongs to same function is written
                                                 with one indentation to the inside. Once you decide
                                                 to code something new, start on a new line with no
                                                 indentation.
                                             •   The indented blocks of code are clear and visibly
                                                 clarifies the logic to solve problem.
       www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
THE DOUBLE EQUALITY
             Learn . Practice .SIGN
                               Upskil at Ybi Foundation
                                         • The equals sign means “assign” or “bind to”.
                                         • For instance, assign 2 to the power of 3 to a
                                               variable y. Hence y, will be equal to 8.
                                         • To check equality between values, use double
                                               equality sign. With possible outcomes as
                                               True or False.
                                         • Values are assigned (in fact, objects are
                                               bound to names) with the equals sign (“=”),
                                               and equality testing is done using two equals
                                               signs (“==”).
        www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
REASSIGN VALUES
             Learn . Practice . Upskil at Ybi Foundation
                                                 • If you assign the value of 1 to a variable
                                                       x, your output after executing x will be 1.
                                                 • After that, if you assign 3 to the same
                                                       variable x, x will be equal to                         3, not 1
                                                       anymore.
                                                 • Python reassigns values to its objects.
                                                       Therefore, remember the last command
                                                       is valid, and older   commands are
                                                       overwritten.
        www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
HELP                             Learn . Practice . Upskil at Ybi Foundation
                                                     • Help in Python is available right in the
                                                           interpreter.
                                                     • To know how an object works use
                                                           help(<object>)
                                                     • Also useful are dir(), which shows you
                                                           all the object’s methods
                                                     • <object>.__doc__                                      shows
                                                           documentation string
       www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
                          Learn . Practice . Upskil at Ybi Foundation
                  Python Data Types
www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
PYTHON LANGUAGE        DATA
            Learn . Practice . UpskilTYPES
                                     at Ybi Foundation
• Numerical Data
     1. Integer
     2. Float
     3. Complex
• Boolean
• Date time      (A date in Python is not a data type of its own, but we can import a module
    named datetime to work with dates as date objects.)
• Sequence Data
    1.   str
    2.   bytes
    3.   bytearray
    4.   Range
•   None Type
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
 ARITHMETIC OPERATORS
              Learn . Practice . Upskil at Ybi Foundation
           Name                            Operator                                          Example
Addition                                         +                            x+y                                10+3 = 13
Subtraction                                       -                           x-y                                10-3 = 7
Multiplication                                   *                            x*y                                10*3 = 30
Division (float division)                        /                            x/y                            10/3 = 3.33
Division (floor
                                                 //                           x // y                             10//3 = 3
division)
Modulus (return the
                                                 %                            x%y                                10%3 = 1
reminder)
Exponentiation                                  **                            x ** y                       10**3 = 1000
           www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
 COMPARISON OPERATORS
             Learn . Practice . Upskil at Ybi Foundation
            Name                                          Operator                                    Example
Equal                                                           ==                                       x == y
Not equal                                                       !=                                        x != y
Greater than                                                     >                                         x>y
Less than                                                        <                                         x<y
Greater than or equal to                                        >=                                       x >= y
Less than or equal to                                           <=                                       x <= y
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session
LOGICAL OPERATOR
             Learn . Practice . Upskil at Ybi Foundation
        Description                                        Operator                                      Example
Returns True if both
                                                               and                               x < 15 and x < 20
statements are true
Returns True if one of the
                                                                 or                                x < 15 or x < 20
statements is true
Reverse the result, returns
                                                                not                          not(x < 15 and x < 20)
False if the result is true
         www.ybifoundation.org (+91) 9667987711 support@ybifoundation.org   Click to Join Live Doubt Session