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

Unit 1 Part 1 - final (1)

The document provides an overview of Python, including its installation via Anaconda and VS Code, as well as its features such as being a high-level, interpreted, and open-source language. It discusses Python's applications in various fields, the use of interactive shells for coding, and the fundamentals of variables, data types, and operators. Additionally, it covers the distinctions between mutable and immutable data types, along with the precedence of operators in expressions.

Uploaded by

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

Unit 1 Part 1 - final (1)

The document provides an overview of Python, including its installation via Anaconda and VS Code, as well as its features such as being a high-level, interpreted, and open-source language. It discusses Python's applications in various fields, the use of interactive shells for coding, and the fundamentals of variables, data types, and operators. Additionally, it covers the distinctions between mutable and immutable data types, along with the precedence of operators in expressions.

Uploaded by

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

Python

03/03/2025 1
Installation of Python
 Anaconda is an open source distribution of Python and other products.
 Anaconda contains Jupyter notebooks.
 Download Anaconda from anaconda.com
 Choose Windows or Mac as per your system and system specifications
 Python can be installed using VS Code also

03/03/2025 2
Basics/Features
 Python is a high-level, general-purpose, and very popular programming language.
 It’s a Free and Open-Source language.
 It is an interpreted language.
 It is case sensitive.
 It is portable and platform independent.
 It has a rich library of predefined functions.
 It is being used in web development, Machine Learning applications, along with all
cutting-edge technology in Software Industry.
 Python language is being used by almost all tech-giant companies like – Google,
Amazon, Facebook, Instagram, Dropbox, Uber… etc.
 It was created by Guido van Rossum, and released in 1991.
 Python programs are generally smaller than other programming languages like Java.

03/03/2025 3
The biggest strength of Python is huge collection of standard library which can be used
for the following:
 Machine Learning
 GUI Applications (like Kivy, Tkinter, PyQt etc. )
 Web frameworks like Django (used by YouTube, Instagram, Dropbox)
 Image processing (like OpenCV, Pillow)
 Web scraping (like Scrapy, BeautifulSoup, Selenium)
 Multimedia

03/03/2025 4
Applications
 Python can be used on a server to create web applications.
 Python can be used alongside software to create workflows.
 Python can connect to database systems. It can also read and modify files.
 Python can be used to handle big data and perform complex mathematics.
 Python can be used for rapid prototyping, or for production-ready software
development.

03/03/2025 5
Entering expression into Interactive Shell
 This window is called the interactive
shell.
 A shell is a program that lets you type
instructions into the computer, much
like the Terminal or Command

03/03/2025 6
Entering expression into Interactive Shell
 Python interactive shell is also known as Integrated Development Environment (IDLE).
With the Python installer, two interactive shells are provided: one is IDLE (Python
GUI) and the other is Python (command line). Both can be used for running simple
programs.
 On Windows, open the Start menu, select All Programs ▸ Python 3.3, and then
select IDLE (Python GUI).
 Enter 2 + 2 at the prompt to have Python do some simple math.
 >>> 2 + 2
 4

03/03/2025 7
 In Python, 2 + 2 is called an expression, which is the most basic kind of programming
instruction in the language.
 Expressions consist of values (such as 2) and operators (such as +), and they can
always evaluate (that is, reduce) down to a single value.
 That means you can use expressions anywhere in Python code that you could also use a
value.

03/03/2025 8
Storing values in variables
 A variable is like a box in the computer’s memory where you can store a single value.
If you want to use the result of an evaluated expression later in your program, you can
save it inside a variable.

Assignment Statements
 You’ll store values in variables with an assignment statement. An assignment statement
consists of a variable name, an equal sign (called the assignment operator), and the
value to be stored.
 If you enter the assignment statement spam = 42, then a variable named spam will have
the integer value 42 stored in it.

03/03/2025 9
 A variable is initialized (or created) the first time a value is stored in it . After that,
you can use it in expressions with other variables and values.
 When a variable is assigned a new value, the old value is forgotten, which is why
spam evaluated to 42 instead of 40 at the end of the example. This is called
overwriting the variable

03/03/2025 10
Variables Name
You can name a variable anything as long as it obeys the following three rules:

 It can be only one word.

 It can use only letters, numbers, and the underscore (_) character.

 It can’t begin with a number.

03/03/2025 11
Valid variable names Invalid variable names
balance current-balance (hyphens are not allowed)

currentBalance current balance (spaces are not allowed)

current_balance 4account (can’t begin with a number)


_spam 42 (can’t begin with a number)
SPAM total_$um (special characters like $ are not allowed)

account4 'hello' (special characters like ' are not allowed)

 Variable names are case-sensitive, meaning that spam, SPAM, Spam, and sPaM are four
different variables. It is a Python convention to start your variables with a lowercase
letter.

03/03/2025 12
Data Types in Python
Data Type refers to the type of data values a variable can hold and the operations that can be
performed on that data.

03/03/2025 13
Data Types in Python
 Number data type stores numerical values only.
 It is further classified in three types: int , float and complex.
 Boolean data type (bool) is a subtype of integer. It consists of two values- True and
False. Boolean True value is non zero, non-null and non-empty. Boolean False is the
value zero.

03/03/2025 14
Data Types in Python
 The data type of a variable can be determined by a built-in function type().

03/03/2025 15
Data Types in Python
 Variables of simple data types like int, float, Boolean etc. hold single values.
 But such variables are not able to hold a list of information like names of months in a
year, names of students in a class, names and numbers in a phonebook etc.
 Python provides data types like tuples, lists, dictionaries and sets.

03/03/2025 16
Data Types in Python
Sequence data type
A python sequence is an ordered collection of items where each item is indexed by an
integer.
They are of three types- Strings, Lists and Tuples.
String
It is a group of characters , characters may be alphabets, digits or special characters
including spaces. String values are enclosed either in single quotation marks or double
quotes. For eg ‘Hello’ , “Hello” both are valid. We cannot perform numerical operations on
strings even if the string contains numerical values.

03/03/2025 17
Data Types in Python
List
It is a sequence of items separated by commas and the items are enclosed in square brackets
[ ]. For example-

03/03/2025 18
Data Types in Python
Tuple
It is a sequence of items separated by commas and items are enclosed in paranthesis ( ).
Once created we cannot change the tuple.

03/03/2025 19
Data Types in Python
Set
It is an unordered collection of items separated by commas and items are enclosed in curly
brackets { }. A set cannot have duplicate entries . Once created, elements of a set cannot be
changed.

03/03/2025 20
Data Types in Python
None
None is a special data type with a single value. It is used to signify the absence of value in a
situation. None supports no special operations and it is neither False nor zero.
If a function returns nothing, then it returns None in Python.

03/03/2025 21
Data Types in Python
Mapping
It is an unordered data type in Python.
Dictionary
Dictionary in Python holds data items in key-value pairs. Items in a dictionary are enclosed
in curly brackets{ }. Dictionaries help to faster access to data. Every key is separated from
its value using a colon :. The key value pairs can be accessed using the key. The keys are
usually strings and their values can be any data type. To access any value in the dictionary
we have to specify its key in square brackets[ ].

03/03/2025 22
Mutable and Immutable Data Types
Variables whose values can be changed after they are created and assigned are called
mutable.
Variables whose values cannot be changed after they are created and assigned are called
immutable. If an attempt is made to update the value of immutable variable the old variable
is destroyed and a new variable is created by the same name in the memory.

03/03/2025 23
Deciding the usage of Data Types
List- Frequent modifications in data. For eg. To store the names of students in a class, it is
easy to update the list when new students join or old leave.
Tuple- No change in data is required. For eg. Names of months in a year.
Set- Uniqueness in data is needed, no duplicacy in data. For eg. List of artefacts in a
museum.
Dictionary- Constant modification in data, need a fast lookup based on a key or a logical
association is present between the key value pair. For eg. Mobile phonebook.

03/03/2025 24
Data Types in Python
The Integer, Floating-point and String data type

03/03/2025 25
Operators
An operator is used to perform mathematical or logical operation on values. The values are
called as operands. For eg. In expression 10+num, 10 and num are operands and + is the
operator.
Different categories of Operators-
 Arithmetic Operators
 Relational Operators
 Assignment Operators
 Logical Operators
 Identity Operators
 Membership Operators

03/03/2025 26
Arithmetic Operators

03/03/2025 27
Arithmetic Operators

03/03/2025 28
Relational Operators
 Relational operator compares the values of the operands on its either side and
determines the relationship among them. Assume the Python variables num1 = 10,
num2 = 0, num3 = 10, str1 = “Good", str2 ="Afternoon" for the following examples:

03/03/2025 29
Relational Operators

03/03/2025 30
Assignment Operators
 Assignment operator assigns or changes the value of the variable on its left.

03/03/2025 31
Assignment Operators

03/03/2025 32
Logical Operators
 There are three logical operators supported by Python.
 These operators (and, or, not) are to be written in lower case only. The logical operator
evaluates to either True or False based on the logical operands on either side. Every
value is logically either True or False. By default, all values are True except None,
False, 0(zero), empty collections "", (), [], {}, and few other special values. So if we
say num1 = 10, num2 = -20, then both num1 and num2 are logically True.

03/03/2025 33
Logical Operators

03/03/2025 34
Identity Operators
 Identity operators are used to determine whether the value of a variable is of a certain
type or not. Identity operators can also be used to determine whether two variables are
referring to the same object or not. There are two identity operators.

03/03/2025 35
Membership Operators
 Membership operators are used to check if a value is a member of
the given sequence or not.

03/03/2025 36
Expression
 An expression is defined as a combination of constants, variables, and operators. An
expression always evaluates to a value.
 Some examples of valid expressions are given below.
 (i) 100 (iv) 3.0 + 3.14
 (ii) num (v) 23/3 -5 * 7(14 -2)
 (iii) num – 20.4 (vi) "Global" + "Citizen"

03/03/2025 37
Precedence of Operators
 Evaluation of the expression is based on precedence of operators. When an expression
contains different kinds of operators, precedence determines which operator should be
applied first.
 Binary operators are operators with two operands.
 The unary operators need only one operand, and they have a higher precedence than the
binary operators.
 The minus (-) as well as + (plus) operators can act as both unary and binary operators,
but not is a unary logical operator.

03/03/2025 38
Precedence of Operators

03/03/2025 39
Precedence of Operators
 Note:
 a) Parenthesis can be used to override the precedence of operators. The expression
within () is evaluated first.
 b) For operators with equal precedence, the expression is evaluated from left to right.

03/03/2025 40

You might also like