PP Unit 1
PP Unit 1
Python Programming
Unit-1
Introduction, Data types and
operators
Contents
• Installation and working with python
• Data types of python
• Variables in python
• Computations and logical statements using python’s operators
• String Operations
Installation and working with python
Introduction to python
• Python is popular programming language, created by Guido van Rossum and first released in 1991
• It was designed with emphasis on code readability and its syntax allows programmers to express
code in fewer lines of code,
• It is an object oriented programming language and it is interpreted.
• There is no need to declare variables in python as we do in C, and it is dynamically typed.
• Its syntax is easy to understand but we can say that ii is slow language as compared to C language.
Why Python?
• Open source and community development, Portable across Operating systems
• Versatile, Easy to read, learn and write
• User-friendly data structures
• High-level language
• Popularly used for machine learning purpose as it has many built in libraries.
• Dynamically typed language
• Portable and Interactive
• Ideal for prototypes – provide more functionality with less coding
• Highly Efficient
• (IoT)Internet of Things Opportunities
Organisations using Python
• Yahoo (Maps)
• Spotify
• Dropbox
• Mozilla
• Pinterest
• Quora
• Google (Components of Google Spider and Search Engine)
Python and its Libraries
• Python has huge amount of additional libraries:
1. Matplotlib (For plotting graphs and charts)
2. NumPy (For Scientific Computing)
3. Pandas (For performing Data analysis)
4. Beautiful Soup (For HTML and XML parsing)
5. SciPy (Engineering applications, science and mathematics)
6. Scikit (For machine learning)
Print Statement
• 1. Simple Print Statement:
print("Hello, World!")
• 5. Using .format() method #Uses format method to insert variables into string
name = "Alice"
age = 30
print("My name is {} and I am {} years old.".format(name, age))
Datatypes and Variables
Data Types
• Python has the following built-in data types:
print(list)
tuple=(1,2,3,4,5)
tuple[0]=10 Here, in tuple we cannot update index [0]
as it is immutable while in lists we can.
print(tuple)
Python Variables
• Variable is a reserved memory location to store values.
• Unlike other programming languages, python has no command for declaring variables.
• Variable is created when you assign value to it.
print(y)
print(type(y))
Operators of python
Operators of python
• Operators are used to perform operations on variables and values.
• Python divides the operators in the following groups:
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Logical operators
5. Identity operators
6. Membership operators
7. Bitwise operators
Arithmetic Operators
• Arithmetic operators are used with numeric values to perform common mathematical operations.
Method Description
Find() Searches the string for a specified value and returns the position of
where it was found.
String functions in Python
Method Description
replace() Returns a string where a specified value is replaced with a specified value.
Index() Searches the string for a specified value and returns the position of where it was
found.
String Functions: Example
• Example:
x=“Gandhinagar University, CE”
Output:
print(x) Gandhinagar University, CE
count=x.count(‘i’) 3
print(count) Gandhinagar University, Ce
t=x.title() gandhinagar university, Ce
GANDHINAGAR UNIVERSITY, CE
l=x.lower()
u=x.upper()
print(t)
print(l)
print(u)
String Functions: Example
# Sample string
sample_string = "Hello, Let’s explore Python string functions.“