python.ppt 1 (1)
python.ppt 1 (1)
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
List[]
Tuples()
Set{}
Dictionaries{ key: value}
It can also called data structure of python or inbuilt data
types.
properties / characteristics
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)
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)
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)