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

python.ppt 1 (1)

The document provides an introduction to Python, highlighting its features, variables, data types, and operators. It covers the basic syntax and methods for lists, including insertion, appending, and removal of elements. Additionally, it explains the use of comments and the input function in Python programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python.ppt 1 (1)

The document provides an introduction to Python, highlighting its features, variables, data types, and operators. It covers the basic syntax and methods for lists, including insertion, appending, and removal of elements. Additionally, it explains the use of comments and the input function in Python programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Name: Neha Verma

Reg id: B1/S25


College: Rimt university
Roll no. : 22-B-CSE-002
Weeks: 6 weeks
Introduction to python

Python is a widely used general-purpose,


high level programming language. It was
created by Guido van Rossum in 1991.
Python is used for server-side web
development, software development.
Features of python

1) High-Level Language.
2) Simple and easy
3) Interpreted language
4) Easy to debug
5) Free and Open Source
6) Portable
Python variables

 Variables are containers for storing data values. A variable is created the
moment you first assign a value to it.
 E.g. x = “apples” output:
a = “Nehu”
Print(x)
Print(a)
 Rules for defining a variable:
a) Variable name must start with letter or underscore character.
b) It cannot start with number.
c) It can only contain alpha numeric character and underscores(A-Z, 0-9, and _ )
d) They are case sensitive.
Universal data types

 Int: Int, or integer, is a whole number, positive or


negative, without decimals, of unlimited length. e.g. 0,
100, -10.
 Float: The float data types are used to store positive and
negative numbers with a decimal point, like 35.3, -2.34
 Boolean : A Boolean variable can have only two values
- True or False.
 String: String is a collection of alphabets, words or
other characters. It include “a”, ‘a’, ”word”.
Comments in python

 Comments are simple sentences that we use to make the


code easier to understand.
 (#) hash is used for single line comment
E.g. #print(“nehu”)
 (“”” “””) used for multi line comments.
E.g. “”” print(“hello”)
this is code
“””
Operators

The operation which is performed is called operators and


the value on which operation is performed is called
operands.
There are various types of operators:
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Logical operators
Arithmetic operators

 Arithmetic operators include addition (+), subtraction


(-), multiplication (*), division (/), and modulus (%).
Code: output:
Assignment operators

 Assignment operators are used for assigning the values.


It includes (=), (+=), (-=), (*=), (/=), (%=)
 Code: output:
Comparison operators

 Comparison operators is used to compare two values or


variables . It includes (==), (>),(<), (<=),(>=),(!=).
 Code: output:
Logical operators

 There are three types of logical operators in


Python: `and`, `or`, and `not`.
 Code: output:
Input() function

 Input function is used to derive input from the user.


 For example: name = input("Please Enter Your Name: ")
Code: output:
Inbuilt data types of python

 List[]
 Tuples()
 Set{}
 Dictionaries{ key: value}
It can also called data structure of python or inbuilt data
types.
properties / characteristics

Properties of list: properties of tuples:


1) It is defined by square brackets[]. 1) It is immutable.
2) Store multiple data types. 2) Defined by circular brackets( ).
3) Ordered and mutable. E.g. a=(1,4,6,7,9)
4) Duplicates are allowed.
e.g. a=[1,2,1,5,7,8]
Properties of set: properties of dictionaries
5) Defined by curly brackets{} 1) Defined by { key: value} pairs
6) Store multiple data types. 2) Duplicates are not allowed.
7) Unordered and immutable(unchangeable). 3) Ordered and mutable.
8) Duplicates are not allowed. E.g. a={ 1: ‘apple’ , 2: ‘ball’}
e.g. a={1,4,6,7,9}
Methods of lists

1) Insert: The insert() method inserts an element to the list at the specified
index.
Code: l1=[1,2,4,2,1, ‘nehu’] output:
l1.insert(2, ‘mohit’)
print(l1)

2) Append: The append() method adds an item to the end of the list.
Code: l1=[1,2,4,2,1, ‘nehu’] output:
l1.append(‘mohit’)
print(l1)
Methods of lists

3) Pop: The list pop() method removes the item at the specified index. If no
parameter is provided to pop then it will remove last element. It takes index
no.
code: l1=[1,2,4,2,1, ‘nehu’] output:
l1.pop( )
print(l1)

4) Remove: It is used to remove the elements. It takes name of elements to


remove.
Code: l1=[1,2,4,2,1, ‘nehu’] output:
l1.remove(‘nehu’)
Print(l1)
Methods of lists

5) Index: The index() method returns the index of the specified element in
the list.
code: l1=[1,2,4,2,1, ‘nehu’] output:
x=list1.index(‘nehu’)
print(x)

6) Extend: It is used to merge two lists.


code: l1=[1,2,4,2,1, ‘nehu’] output:
l2=[2,4,6,7,9]
l1.extend(l2)
print(l1)
Methods of lists

7) Count: It is used to count the counting the no. of occurrence of any elements.
Code: l1=[1,2,4,2,1, ‘nehu’] output:
x=l1.count(1)
print(x)

8) reverse: used to reverse the elements.


Code: l1=[1,2,4,2,1, ‘nehu’] output:
l1.reverse( )
Print(l1)

You might also like