Posts

 CHECKING IF ELEMENTS EXIST IN LIST👏 test_list = [ 1 , 6 , 3 , 5 , 3 , 4 ]   print ( "Checking if 4 exists in list ( using loop ) : " )   for i in test_list :     if ( i == 4 ) :         print ( "Element Exists" )   print ( "Checking if 4 exists in list ( using in ) : " )   USING IN if ( 4 in test_list ):     print ( "Element Exists" )    
 SWAP POSITION IN LISTđź‘€ # Python3 program to swap elements # at given positions # Swap function def swapPositions(list, pos1, pos2): list[pos1], list[pos2] = list[pos2], list[pos1] return list # Driver function List = [23, 65, 19, 90] pos1, pos2 = 1, 3 print(swapPositions(List, pos1-1, pos2-1))
EVEN NUMBER IN THE LIST # Python program to print Even Numbers in a List # list of numbers list1 = [ 10 , 21 , 4 , 45 , 66 , 93 ] # iterating each number in list for num in list1 :     # checking condition     if num % 2 == 0 :         print ( num , end = " "
 CLASS class car: def __init__ ( self , name , speed , mileage , ): self .name = name self .speed = speed self .mileage = mileage NOW from car import car car = car( "kia" , "66" , "10" ) print (car.mileage) OUTPUT: 10
 CLASSES AND OBJECT class Student: def __init__ ( self , name , major , gpa , is_on_probation): self .name = name self .major = major self .gpa = gpa self .is_on_probation = is_on_probation IN APP.PY FILE from Student import Student student1 = Student( 'Utkarsh' , "Business" , 9.9 , False ) print (student1.name) OUTPUT= utkarsh
 APP USING FILE import random feet_in_mile = 500 meters_in_kilometers = 1000 beatles = [ "John Lennon" , "Paul McCartney" , "George Harrison" , "Ringo Star" ] def get_file_ext (filename): return filename[filename.index( "." ) + 1 :] def roll_dice (num): return random.randint( 1 , num) IN useful_tools files import useful_tools print (useful_tools.roll_dice( 10 ))
 TRY AND EXCEPT try : number= int ( input ( "Enter the number" )) print (number) except : print ( "Invalid Input" )đź’€