Python Environment Setup and Essentials-1
Python Environment Setup and Essentials-1
Python Environment Setup and Essentials-1
Essentials
Prepared by
Narasimha N
Technical Trainer
Outline
◈ Installation of Anaconda
◈ Data types with Python
◈ Basic Operators
◈ Functions
Installation of Anaconda
Visit the Anaconda website:
Go to the Anaconda website at
https://www.anaconda.com/products/individual and navigate to
the individual edition download page.
Choose the correct installer:
Make sure to download the installer
appropriate for your operating system (Windows, macOS, or
Linux). Anaconda supports both 32-bit and 64-bit systems.
Contd..
Contd..
o Download the installer: Click on the download link for the version
of Anaconda you want to install. Wait for the download to complete.
o Select the installation location: Choose the location where you want
to install Anaconda. By default, it will be installed in your user
directory.
• Sequence Types:
• str: Strings, e.g., "hello", 'world'.
• list: Ordered, mutable sequences, e.g., [1, 2, 3], ['a', 'b', 'c'].
• tuple: Ordered, immutable sequences, e.g., (1, 2, 3), ('a', 'b', 'c').
Contd..
• Mapping Type:
• dict: Key-value pairs, e.g., {'name': 'John', 'age': 30}.
• Set Types:
• set: Unordered collection of unique elements, e.g., {1, 2, 3}, {'a',
'b', 'c'}.
• frozenset: Immutable version of set, e.g., frozenset({1, 2, 3}).
• Boolean Type:
• bool: Represents truth values (True or False).
• None Type:
• None: Represents the absence of a value or null.
Basic Operators
• Arithmetic Operators:
• Addition: +
• Subtraction: -
• Multiplication: *
• Division: /
• Floor Division: //
• Modulus: %
• Exponentiation: **
Contd..
• Assignment Operators:
• Assignment: =
• Addition Assignment: +=
• Subtraction Assignment: -=
• Multiplication Assignment: *=
• Division Assignment: /=
• Modulus Assignment: %=
• Exponentiation Assignment: **=
Contd..
• Comparison Operators:
• Equal to: ==
• Not equal to: !=
• Greater than: >
• Less than: <
• Greater than or equal to: >=
• Less than or equal to: <=
Contd..
• Logical Operators:
• Logical AND: and
• Logical OR: or
• Logical NOT: not
Contd..
• Bitwise Operators:
• Bitwise AND: &
• Bitwise OR: |
• Bitwise XOR: ^
• Bitwise NOT: ~
• Left Shift: <<
• Right Shift: >>
Contd..
• Membership Operators:
• In: Checks if a value exists in a sequence.
• Not in: Checks if a value does not exist in a sequence.
Contd..
• Identity Operators:
• is: Checks if two variables refer to the same object.
• is not: Checks if two variables do not refer to the same object.
Functions in Python
In Python, functions are blocks of reusable code that perform a specific
task. They help in organizing code, promoting reusability, and making
the code modular.
• Built-in Functions: These functions are built into the Python
language and are available for use without any import or additional
setup. Examples include print(), len(), input(), type(), etc.
Contd..
• User-Defined Functions: These functions are defined by the user to
perform specific tasks. They are created using the def keyword,
followed by the function name, parameters (if any), and a block of
code.
Contd..
• Function with Parameters:
Functions can accept parameters, which are variables
passed into the function. These parameters can be used within the
function's code to perform operations.
Contd..
• Function with Return Value:
Functions can return a value using the return
statement. The returned value can be stored in a variable or used directly in
the code.
Contd..
• Recursive Functions:
Recursive functions are functions that call themselves
within their own definition. They are useful for solving problems that
can be broken down into smaller, similar subproblems.
Contd..
• Lambda Functions:
Lambda functions, also known as anonymous
functions, are one-line functions without a name. They are typically
used for simple, single-expression tasks.