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" )
Posts
- Get link
- X
- Other Apps
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
- Get link
- X
- Other Apps
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 ))