Posts

Tuple using Python:

Image
 Tuple using Python: #tuple """ Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Tuple has rounded brackets """ #defining tuple import null as null tuple=( 1 , 2 , 3 , 4 , 5.222 , 6 , "ff" , "qqqqqqqqqqqqqqqqqq" ,null) print ( "tuple:" ,tuple) tuple1=( 9 , 11 , 22 , 33 , 9 , 9 , 9 ) print ( "tuple1=(9,11,22,33)=" ,tuple1) #length of tuple1 n= len (tuple1) print ( "length of tuple1=" ,n) #count 9 number of times present in tuple1 print ( "count 9 number of times present in tuple1=" ,tuple1.count( 9 )) Output: tuple: (1, 2, 3, 4, 5.222, 6, 'ff', 'qqqqqqqqqqqqqqqqqq', <module 'null' from 'C:\\Python\\Python390\\lib\\site-packages\\null.py'>) tuple1=(9,11,22,33)= (9, 11, 22, 33, 9, 9, 9) length of tuple1= 7 count 9 number of times present in tuple1= 4

List Operations using python

Image
List Operations Code:   #list example list1=[ "a" , "b" , "c" , "d" , "e" ] print (list1) print ( " \n data type for list1: \t " , type (list1)) #finding index number x=list1.index( "c" ) print ( " \n index of x: " ,x) #append element list1.append( 1 ) print ( " \n list1=" ,list1) #index numbers print ( " \n list1[0]=" ,list1[ 0 ], " \n list1[2]=" ,list1[ 2 ]) #insert new element in list list1.insert( 10 , "zggggg" ) print ( " \n updated list: " ,list1) #update list element list1.insert( 2 , "xyz" ) print ( "Updated list=" ,list1) Output: ['a', 'b', 'c', 'd', 'e'] data type for list1: <class 'list'> index of x: 2 list1= ['a', 'b', 'c', 'd', 'e', 1] list1[0]= a list1[2]= c updated list: ['a', 'b', 'c', 'd...

creating list in python

Image
Creating list in python  Code: #list example list1=[ "a" , "b" , "c" , "d" , "e" ] print (list1) print ( " \n data type for list1: \t " , type (list1)) Output: ['a', 'b', 'c', 'd', 'e'] data type for list1: <class 'list'>

First code in python

Image
First code: print("hi") Simple code: #single line comments """ ***** this is multi line comment ***** """ print ( "#single line comments" ) num1= 10 #number print ( "type(num1) : " , type (num1)) num2= 12 print ( "type(num2) : " , type (num2)) str= "hi" print ( "type(str) : " , type (str)) float_num= 1.00 print ( "type(float_num) : " , type (float_num)) print ( "num1 : " ,num1) print ( "num2 : " ,num2) print ( "str :" ,str) print ( "float_num :" ,float_num) add= 2 + 2 print ( "add :" ,add) #single line comment Output: #single line comments type(num1) : <class 'int'> type(num2) : <class 'int'> type(str) : <class 'str'> type(float_num) : <class 'float'> num1 : 10 num2 : 12 str : hi float_num : 1.0 add : 4 Screenshot: