for i in range(100,300): for j in range(2,i+1): if i % j == 0: break else: print(i) 10 ==> 1, 2, 5, 10 20 ==> 1,2,4,5,10,20 ================================================ DATA STRUCTURES ================= FACEBOOK: REGISTARTION: NAME : STRING USER NAME: STRING MOBILE : INTEGER DOB : STRING AGE : INTEGER GENDER : STRING ADDRESS : STRING MAIL : STRING REGISTER OUR COMPUTER ===> FACEBOOK SERVER IN THE FORMAT OF THE TABLE STRING DATA STRUCTURE ======================= WHAT IS STRING =============== A GROUP/COLLECTION OF CHARACTERS WHICH ENCLOSED WITH SINGLE QUOTES OR DOUBLE QUOTES. EX: 'PYTHON' , "PROGRAMMING" ==> The Characters are of any type: might be with: alphabets (any case), digits (0 to 9) and special characters etc. STRING DEFINITION ================ ==> two ways to define the strings: 1) compile time definition ==> variable can be executed with fixed data in the entire program ==> with assignment operator 2) run time definition ==> variable can be accept different values for every execution time of the program. input(), str(input()) # string definition # compile time definition str_data = 'python' str1_data = "Programming" str2_data = "123455" str3_data = "@#$%" str4_data = 'python@12343' # run time definition of the string str5_data = input("Enter a string data:") print(type(str_data),type(str1_data),type(str2_data),type(str3_data),type(str4_data)) print(str_data,str1_data,str2_data,str3_data,str4_data) print(type(str5_data)) print(str5_data) ================================================== MULTI LINE STRING ================= ==> to define the multi-line strings: triple quotes are used. Ex: '''Python is High-level, General-purpose, Object Oriented Programming language.''' """Python is High-level, General-purpose, Object Oriented Programming language.""" ==> In between multi-line string, we can allowed to use: single quotes double quotes. Ex: """Python's Features are: 'High Level' "Objecte Orienetd" """ a = ''' Python is High-level, general purpose, object oriented programming langauge ''' b = """ Python is High-level, general purpose, object oriented programming langauge """ c = """Python's Features are: 1) High Level Programming langauge. 2) 'General Purpose Programming Langauge.' 3) "Object Oriented Programming language." """ print(type(a),type(b)) print(a) print(b) print(type(c)) print(c) Note: ==== 1) adding of double quotes in between double quotes ==> not possible. 2) adding of single quotes in between single quotes ==> not possible ==> to add: \start_quotes ........ \end_quotes d = 'Python\'s' e = 'Python is \'High level programming language\'' f = "python is 'High Level Programming language.'" g = 'Python is "High level" language' print(d) print(e) print(f) print(g) ========================================================== STRING DATA ACCESSING ====================== ==> possible in two ways: 1) Indexing ==> accessing with individual characters 2) Slicing ==> accessing the part of the string with group of characters [] ==> slice operator 1) Indexing ========= ==> with two ways: 1) using positive index ==> to access the string charcters from left to right ==> called as "forward accessing" ==> default start value : 0 ==> end with: length of string - 1 ==> Range of positive indexing ==> 0 to length_string - 1 ==> if the index value from out of range ==> error 2) using negative index ==> to access the string characters from right to left ==> called as "reverse accessing" ==> default start value: -1 ==> default end value : -length_string ==> range of negative indexing ==> -1 to -str_length Syntax: str_data[index value] str_data = input("Enter a string:") print("The Size of the string = ",len(str_data)) # positive indexing ==> forward access print(str_data[0]) print(str_data[1]) print(str_data[2]) print(str_data[3]) print(str_data[4]) print(str_data[5]) print() # negative indexing ==> reverse access print(str_data[-1]) print(str_data[-2]) print(str_data[-3]) print(str_data[-4]) print(str_data[-5]) print(str_data[-6]) 2) Slicing ======= Syntax: str_data[start:stop] ==> slicing start at "start" value and end with "stop-1" value str_data[start:stop:step] ==> slicing start with "start" value and end with "stop-1" value with the difference of "step" str_data[:stop] ==> by default, slicing can start with first character and end with "stop-1" value str_data[start:] ==> slciing can start with "start" value and end with "last" by default str_data[::] ==> start with first character and end with last str_data[::step] ==> start with first character and end with last with difference of step value. str_data = "Python programming" print(str_data[0:6]) print(str_data[-1:-10:-1]) print(str_data[-10:-1]) print(str_data[0:len(str_data)+1 : 3]) print(str_data[0::3]) print(str_data[::3]) print(str_data[:-1:1]) print(str_data[::]) print(str_data[::-1]) print(str_data[::4]) STRING OPERATIONS ================== 1) FINDING THE LENGTH OF THE STRING ================================== len() ==== ==> used to find the total number of characters of the given string Syntax: len(str_data) str_data = input("Enter a string value:") print(type(str_data)) print("The length of the string = ",len(str_data)) PRACTICE