STRING HANDLING =============== String Slicing: =============== ==> Acquiring of the part from the string is called as "String Slicing". ==> Slice operator ==> [] Syntax: string-object-name[start-index : end-index : step] s = "Python Fullstack" # P = 0, y = 1, t = 2 h = 3 o = 4 n = 5 = 6 F = 7 u = 8... print(s) # full string print(s[::]) # full string # start-index ==> empty, string slicing by default from the 1st character # end-index ==> empty, string slicing can stop at last character by default # step ==> empty, step difference '1' print(s[::1]) # full string print(s[0:6]) # from end-index, end-index-1 print(s[:6]) print(s[7:]) print(s[::-1]) # start at '0' reverse string print(s[::2]) print(s[-1:-10:-1]) print(s[10:0:-1]) ========================================================== String Concatenation: ===================== ==> Joining of two or more strings into one string is called as "String Concatenation". ex: "Python" "Full" "Stack" "PythonFullStack" ==> Symbol/Operator: + Syntax: str-obj1 + str-obj2 + str-obj3 + .... All datatypes: classified into two types: 1) Mutable 2) Immutable Integer, float, complex, Boolean, string ==> Immutable Mutable: ======== The value of the variable after the definition we can consider to modify ex: List, set, dictionary etc. Immutable: ========== The value at variable cannot allow for the modification after the definition are called as "Immutable Data objects". s1 = "Python " s2 = "Full" s3 = "stack" s = s1+s2+s3 print(s) ====================================================== String Length: ============== len() ==== return the total number of characters of the string Syntax: len(str-object-name) Note: ==== len() is not only for strings len() for any collection datatype. s = "Python Fullstack" print("The total number of characters = ",len(s)) ========================================= How to define the string in run-time/How to define the string dynamically? =========================================================================== S = "string" ==> compile time definition input() ==> allow to take the value in run time with string format by default. Syntax: str-obj = input("text") s = "Python Fullstack" # compile time print("The total number of characters = ",len(s)) s1 = input("Enter a string:") print(s1) print(type(s1)) print(id(s1)) print(len(s1))