0% found this document useful (0 votes)
13 views12 pages

Python Installation and Basics Guide

The document provides a comprehensive guide on installing Python and setting up a virtual environment using Anaconda, along with an overview of Python basics including character sets, identifiers, keywords, operators, expressions, statements, comments, and indentation. It also covers data types, type conversion, control structures, lists, dictionaries, and popular Python packages for various applications. Key concepts such as loops, list manipulation, and the use of libraries for web development and data processing are highlighted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

Python Installation and Basics Guide

The document provides a comprehensive guide on installing Python and setting up a virtual environment using Anaconda, along with an overview of Python basics including character sets, identifiers, keywords, operators, expressions, statements, comments, and indentation. It also covers data types, type conversion, control structures, lists, dictionaries, and popular Python packages for various applications. Key concepts such as loops, list manipulation, and the use of libraries for web development and data processing are highlighted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Installation of Python

1. To install Python virtual environment – JUPYTER Notebook using ANACONDA, type the
link: [Link]

2. Click on Download
3. Begin the installation process.
4. Getting through the License-Agreement

Python Basics
Python Character Set

Character set is a set of valid characters that a language can recognise. A character
represents any digit, alphabet and special symbol. The character used in a Python source
program belongs to unicode standard.​
Python supports the following character set.​
Alphabets – A to Z (uppercase), a to z (lowercase)​
Digits – 0 to 9

Identifiers

The identifier is a sequence of characters taken from Python character set.​


Identifiers are used to give the name to data items like variables, objects, classes, functions,
arrays, etc., to specify their names.

The rules in Python for identifiers are

1.​ Only alphabets, digits and underscores are permitted.


2.​ Identifier name cannot start with a digit.
3.​ Keywords cannot be used as identifier.
4.​ Uppercase and lowercase letters are distinct because Python is case sensitive
language.
5.​ Special characters are not allowed.

Keywords

Keywords are predefined reserved words by the programming language that have some
special or predefined meanings. These are reserved for special purpose and must not be
used as identifier names. Some commonly used keywords in Python, e.g for, if , print, true,
and , in as etc.
Operators

Operators perform a specific task/computation when applied on variable or some other


objects in an expression (known as operands). Operators are used in programs to operate
on data and variables.​
There are two types of operators as follows:

Expressions

An expression is a combination of operators, constants and variables as per rule of the


language. Any part in a program which can have a value, is an expression. It will have
operands and operators together to produce a value.

Statements

A statement is a logical instruction, which Python interpreter can read and execute. In
Python, it could be an expression or assignment statement. The assignment statement is
fundamental to Python.
e.g
if(x==y):
print(“x is equal to y”)

Comments

Comments are non-executable statements that are ignored by the interpreter or compiler
and are not executed by the computer.​
Comments are written to explain what each block of the program is doing.​
There are two types of comments used in programs as follows​
(a) Single line comment A single line comment starts with symbol.​
e.g. Here is define the function of addition​
(b) Multi-line comment A multi-line comment starts with a “‘symbol and ends with”.​
e.g. x = 20 “Here we initialise the value of variable x as 20 “‘

Indentation

Indentation indicates the relationship between various statements and thus allow us to get a
better picture of the overall organisation and structure of the solution given in the program.
It improves the readability of the program.

E.g
if(x==y):
print(“x is equal to y”)
print(lets move to the next statement”)

Variable is a container object that stores a meaningful value that can be used throughout
the program.
Each variable has a specific type, which determines the size and layout of the variable’s
memory, the range of values that can be stored within that memory and the set of
operations that can be applied to the variable. A variable can be created anywhere in Python
program.
E.g
a=10
city=”Gurgaon”

Data types in Python


Type Conversion The process of converting the value of one data type (integer, string, float,
etc.) to another data type is called type conversion. Python has two types of type
conversion.
1. Implicit Type Conversion
2. Explicit Type Conversion
Implicit Type Conversion In Implicit type conversion, Python automatically converts one
data type to another data type. This process doesn't need any user involvement.
E.g
simple_interest= 900
print("value of simple interest : ", simple_interest)
print("datatype of simple interest : ", type(simple_interest))

Output
value of simple interest : 900.50
datatype of simple interest : <class, ‘float’>

Explicit Type Conversion In Explicit Type Conversion, users convert the data type of an
object to required data type. We use the predefined functions like int(), float(), str(), etc to
perform explicit type conversion. This type of conversion is also called typecasting because
the user casts (changes) the data type of the objects.
E.g
Birth_day = 10
Birth_month = "July"
print("data type of Birth_day before type casting :", type(Birth_day))
print("data type of Birth_month : ", type(Birth_month)) Birth_day = str(Birth_day)
print("data type of Birth_day after type casting :",type(Birth_day))

Output
data type of Birth_day before type casting : <class,’integer’.
data type of Birth_month : <class,’string’>
data type of Birth_day after type casting :< class,’string’>

Control Structure
If-elif-else statement

Nested If

range( ) Function

The range( ) function is used to generate a sequence of numbers overtime. At its simplest, it
accepts an integer and returns a range object (a type of iterable).

The range ( ) function has two forms as follows:​


(i) range (stop)​
stop number of integers to generate, starting from zero. e.g. range (5) = [0,1,2,3,4]
(ii) range ([start,] stop [,step])

●​ start starting number of the sequence.


●​ stop generate numbers upto, but not including this number.
●​ step difference betweèn each number in the sequence.

Iterative Statements

Iterative statements or loops enable a program with a cyclic flow of logic. Each statement
which is written under the scope of a looping statement gets executed the number of times
the iteration/looping continues for. There are two basic types of looping statements
available in Python, they are as follows.

1. while loop

A while loop tests for its ending condition before executing the statements enclosed in the
loop body even the first time.​
So, if the ending condition is met when the while loop beings, the lines of instructions its
contains will never be carried out. This loop is also known as Entry control loop.

A while loop continues iteration cycle till its loop condition is evaluated as true. If the
loop-condition is false for the first time iteration, then loop will not execute even once.
for loop

The for statement encloses one or more statements that form the body of the loop, the
statements in the loop repeat continuously a certain number of times.​
This loop is also an entry control loop, as condition is checked before entering into the
scope of the loop.

Introduction to Lists
a = [1,2.3,"Hello"]
How to create a list ?
# nested list

student marks = [ ["Aditya", "10-A", [ "english",75] ]

How to access elements of a list ?


A list is made up of various elements which need to be individually accessed on the basis of the
application it is used for. There are two ways to access an individual element of a list:
1) List Index 2) Negative Indexing

Adding Element to a List

We can add an element to any list using two methods :


1) Using append() method e.g [Link](4)
2) Using insert() method e.g [Link](0, 'Kabir')
3) Using extend() method e.g [Link]([8, 'Artificial', 'Intelligence'])

Removing Elements from a List

Elements from a list can removed using two methods :


1) Using remove() method e.g [Link](5)
2) Using pop() method e.g [Link](5)

Slicing of a List

Dictionary

Dictionary is an unordered collection of key-value pairs. It is generally used when we have a


huge amount of data. Dictionaries are optimized for retrieving data. We must know the key
to retrieve the value.
In Python, dictionaries are defined within braces {} with each item being a pair in the form
key: value. Key and value can be of any type.
Declaring Dictionary
student={"Name":"Arnav","Class":"X","Section" :"A"}
print(student)

Output
student={"Name":"Arnav","Class":"X","Section" :"A"}

Python Packages
Python has a rich ecosystem of libraries and packages that extend its functionality for
various purposes. Here are some widely used Python libraries and packages:

Usage Machine learning, data mining,

●​ Beautiful Soup Library for pulling data out of HTML and XML files. It provides
Pythonic idioms for iterating, searching, and modifying the parse tree. Usage
Web scraping.
●​ Django High-level web framework for building web applications quickly. It
follows the model-view-controller (MVC) architectural pattern. Usage Web
development.
●​ Flask Lightweight web framework. It simplifies web application development by
providing tools and libraries needed.
Usage Web development.

●​ NLTK (Natural Language ToolKit) Library for working with human language data.
It provides easy-to-use interfaces for tasks such as classification, tokenization,
stemming, tagging, parsing, and more.
●​ Usage Natural Language Processing (NLP), text mining.
●​ OpenCV (Open Source Computer Vision) Library for computer vision and
machine learning. It provides tools for image and video analysis.
●​ Usage Computer vision, image and video processing.

You might also like