Monday, March 2, 2020

INTRODUCTION for....PYTHON

Basic for PYTHON.....
-March 2.3.2020

CONCEPT:
Introduction for Python.....and basic method.
today class for..
#LIST  []
#SORTING
#TUPLES ()
#SET  {}


                              #LIST []

Example 1:

fruits=['apple', 'orange', 'cherry']
print(fruits)
output:
('apple', 'orange', 'cherry')

Example 2:

fruits=['apple','orange','cherry']
print(fruits[1])
output:
orange

Example 3:

fruits=['apple','orange','cherry']
print(fruits[1:3])
output:
orange, cherry

Example 4:
fruits=['apple','orange','cherry']
print(fruits[-1])
output:
cherry

Example 5:

fruits=['apple','orange','cherry']           
fruits[1]='banana'
print(fruits)
output:
['apple','banana','cherry']

Example 6:

 
fruits.append('banana')                       #Append used for  JOIN ONE STRING.
print(fruits)
output:
['apple','orange','cherry', 'banana']

                                                     #SORTING

number=[11, 2, 20, 0]
number.sort()
print(number)                                       #SORTING IS USED FOR ARRANGING THE  NUMBER 
 output:                                                     FROM ASCENDING  TO DESCENDING
[0, 2, 11, 20]

Example 2:

number=[11, 2, 20, 0]
number.sort(reverse=true)
print(number) 
output:
[ 20, 11, 2, 0]   

                                                   #TUPLES ()


fruits=['apple','orange','cherry']
number=[11, 2, 20, 0]
print(fruits+number)                     #A Tuples is a collection  which is order and  UNCHANGEABLE.
output:
['apple','orange','cherry', 11, 2, 20, 0]

                                                   #SET{}

fruits={'apple','orange','cherry'}
print(fruits)
number=(11, 2, 20, 0)                           #Set  is Use for Changing the order
print(number)
output:
{'apple','orange','cherry'}
(11, 2, 20, 0)


                                                







 




No comments:

Post a Comment