Week 02 Introduction to Python Programming- Subash
Week 02 Introduction to Python Programming- Subash
• Literally someone who uses the computer or the smart-phone or the e-reader.
• Often is not an expert; he or she just owns the device and knows how it works.
• Example: Ali is an educated person, but computers are not his area of expertise
‹#›
• See computers as a set of tools - word processor, spreadsheet, map, todo list, etc.
Programmers
3
5/5/2024
Python Programming
Python Programming Language was created by
Guido van Rossum. It was first released in the
early 1990s.
Python Programming
This Photo by Unknown Author is
licensed under CC BY-SA
4
5/5/2024
Features of Python
Easy and Simple to use
●Due to its Simple Syntax, it is easy and straight forward and much the same as
the English language.
Python Programming
●Python is freely available for everyone.
5
5/5/2024
Continue…
Large sets of library and packages
●It provides a vast range of libraries for the various fields such as machine learning, web
developer, and for the scripting. Examples Pandas, Numpy, Keras, Pytorch, Django,
Matplotlib, Scikit-learn SciPy etc.
Python Programming
Reference sites
6
5/5/2024
Why easy and simple to use?
import java.util.Scanner; Java program for adding two
public class JavaExample { numbers by taking inputs
public static void main(String[] args) { from user.
double num1, num2, sum;
Scanner sc = new Scanner(System.in);
System.out.print("Enter First Number: ");
num1 = sc.nextDouble();
System.out.print("Enter Second Number: ");
num2 = sc.nextDouble();
sc.close();
Python Programming
sum = num1 + num2;
System.out.println("Sum of "+num1+" and "+num2+" is:
"+sum);
}
}
7
5/5/2024
Python program for adding two
numbers by taking inputs from user.
sum = a + b
Python Programming
8
Python is Dynamically Typed
5/5/2024
Language
a = 15
<type ‘int’>
a = 3.0
Python Programming
<type ‘float’>
9
Why Python?
‹#›
• easy to learn, • C is much faster but
• relatively fast, much harder to use.
• Java is about as fast
• object-oriented, and slightly harder to
• strongly typed, use.
• widely used, and • Perl is slower, is as
• portable. easy to use, but is not
strongly typed.
5/5/2024
Application areas of Python
• Web Applications
• Network Applications
• Games Development
• Data Analysis Applications
• Machine Learning Applications
• Artificial Intelligence, Deep Learning, Neural Network Applications
• IOT
• Data Science
Python Programming
Hence it is called General Purpose Programming Language
11
Compiling and Interpreting
• Many languages require you to compile (translate) your program into a form that
the machine understands.
‹#›
• Python is instead directly interpreted into machine instructions.
5/5/2024
Variables
It is a container to hold data.
Python Programming
13
5/5/2024
Rules for Naming
• The variable's first character must be an underscore or alphabet and remaining
character can have alphabets, digits, and underscore(_).
• White space and special characters (!, @, #, %, etc.) are not allowed.
Python Programming
Generally, the name of the variable should be written in lowercase.
14
5/5/2024
Variable – Python Example
Create a variable number = 10
number = 10
Replaced or reassign the value of number = 2.5
the variable.
a, b, c = 3, 3.5, “Python”
Assigning multiple values to
multiple variables:
Python Programming
a = b = c = “I love Python”
Assigning same values to multiple
variables:
15
5/5/2024
Constant
• Is a type of variable whose value cannot be changed.
• It is helpful to think of constants as containers that hold
information which cannot be changed later.
• Refer to names associated with values that never change
during a program’s execution.
• Fixed values such as numbers, letters, and strings are called
“constants” - because their value does not change.
Python Programming
• Constants are usually declared and assigned in a module
16
5/5/2024
Commenting in Python
• Comments can be used to explain Python code.
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing code.
#This is a comment
print("Hello, World!")
Python Programming
17
5/5/2024
Python Data Types
Every value has a datatype, and variables can hold values.
length = 10
radius = 10.1
c = 2+ 2.3j
is_prime = False
name = "Subash"
Python Programming
list1 = [1, "Subash", "Python", 40]
t = ("hi", "Python", 2)
18
5/5/2024
Python Keywords
Python keywords are unique words reserved with defined meanings and functions
that we can only apply for those functions.
Python Programming
assert del global not with
async elif if or yield
19
5/5/2024
Python Operators
• Arithmetic Operators
• Assignment Operators
• Logical Operators
• Bitwise Operators
• Membership Operators
• Identity Operators
Python Programming
20
Arithmetic Operators
Python Programming
22
5/5/2024
Logical Operators
Used to combine conditional statements
Python Programming
23
5/5/2024
Bitwise Operators
Works on bits and performs bit by bit operation
Python Programming
1 1 1 1 0
24
5/5/2024
Example of Bitwise Operators
1 1 1 0 0 0 (56) 1 1 1 0 0 0 (56)
& 1 0 0 0 0 1 (33) | 1 0 0 0 0 1 (33)
1 0 0 0 0 0 (32) 1 1 1 0 0 1 (57)
1 1 1 0 0 0 (56) 1 1 1 0 0 0 (56)
^ 1 0 0 0 0 1 (33) >> 2
Python Programming
0 1 1 0 0 1 (25) 1 1 1 0 (14)
25
5/5/2024
Membership Operator
Test for membership in a sequence such as strings, lists or tuples.
Python Programming
26
5/5/2024
Identity Operator
Compare the memory locations of two objects.
Python Programming
27
Operator Precedence
‹#›
• Variable types don’t need to be declared.
• Python figures out the variable types on its own.
• Special use of + for string concatenation and % for string formatting (as in C’s printf)
Interactive
• You type directly to Python one line at a time, and it
‹#›
responds
Script
• You enter a sequence of statements (lines) into a file
using a text editor and tell Python to execute the
statements in the file
5/5/2024
Expression
A data value or set of operations to compute a value.
Example:
1+4*3
Python Programming
x = 1 + 2 * 3 - 4 / 5 ** 6 //what will be the output??
31
5/5/2024
Type Conversion
Type conversion is the process of converting data of one type to
another.
A = 192
B = “50”
C = A + int(B) // Converting str into int datatype
Python Programming
32
5/5/2024
Python Installation Guide
Python Programming
37
5/5/2024
Download and install python from
https://www.python.org/downloads/
Python Programming
38
Check Python Version
5/5/2024
python --version
Python Programming
39
PIP installation (Recommended)
5/5/2024
https://pip.pypa.io/en/stable/installation/
PIP is a package manager for Python.
Python Programming
40
5/5/2024
Install Jupyter Notebook
Go to Jupyter Notebook Website
Python Programming
jupyter notebook
41
5/5/2024
Importance of IDE
IDLE is an integrated development environment (IDE).
Python Programming
3. Debugger : For taking control of the execution of a
program to aid in finding program errors
42
Integrated Development
5/5/2024
Environment
Most widely used IDE for python programming are:
• Google Colab
Python Programming
• Jupyter Notebook (recommended) (Install Jupyter Notebook without Anaconda)
43
5/5/2024
Fundamental Concepts of Python
Programming
Python Programming
44
5/5/2024
First Program in Python
open terminal or cmd or python shell
OR
Python Programming
open IDLE
45
5/5/2024
How to take input from user?
input() function is used to take any input from user.
Python Programming
46
Tutorial-02: Fundamentals of
5/5/2024
Python Programming
1.Install python and IDLE.
2.Write the first program in python.
3.Take an input from user and print it.
4.Take two float numbers from user and performs
arithmetic operations
Python Programming
47
5/5/2024
Variables and Datatypes
• Python type() function prints what type of data structures are used to store the
data elements in a program.
Python Programming
48
Arithmetic Operators
Python Programming
6. Does Python have data types? Explain in detail.
53
END