# WAP IN PYTHON CHECK WHETHER THE STRING IS PALINDROME STRING OR NOT. # s = "level" # rev_s = "level" # rev_s == s: # palindrome # Otherwise ==> not palindrome s = input("Enter a string:") # "level" print("The Given string =",s) print(id(s)) # reverse of the string # print(id(s[::-1])) rev_str = s[::-1] # start index in the string slicing: by default, the slicing can start from index '0' # end index in the string slicing: the slicing can end at the last character. print(s) print(id(s)) if rev_str == s: print("The string is palindrome") else: print("The string is not palindrome.") ==================================================== String Comparison: ================== Note: ===== Python-2: cmp() Python-3: cmp() got deprecated. Relational Operators: ===================== Operator ==> symbol which can denote an operation. Ex: + == addition Relational Operators: <, >, <=, >=, ==, != String with characters: "Ashok IT" each character can be represented with one integer value (ASCII value/Uni Code) ASCII ==> 256 values ==> 0 to 255 ex: A to Z ==> 65 to 90 a to z ==> 97 to 122 Unicode ==> 65536 ==> 0 to 65535 A to Z ==> 65 to 90 a to z ==> 97 to 122 ord(): ===== ==> accept a character and return a Unicode value for that corresponding character. Syntax: ord(character) print(ord('a')) print(ord('A')) print(ord('z')) print(ord('Z')) Ex: "abc" < "Abc" ==> False 97 < 65 s1 = "abcd" s2 = "ABCD" s3 = "abcD" s4 = "abcd" print(s1 == s3) # False print(s1 == s4) print(s1 < s2) ==================================== Removing of blank spaces from the string: ========================================= "Python Programming" 1) we cannot remove the white space between the string. 2) we can remove the white space from the beginning of the string and/or ending of the string. " Python programming " ==> three functions: 1) strip() ==> can remove blank spaces from beginning and ending part of the string Syntax: str-obj-name.strip() 2) rstrip() ==> can remove the spaces from right side of the string Syntax: str-obj-name.rstrip() 3) lstrip() ==> can remove the spaces from left side of the string Syntax: str-obj-name.lstrip() s1 = "Python Programming" s2 = " Ashok IT " print("The Strings are = ") print(s1) print(s2) print(s1.strip()) print(s1.lstrip()) print(s1.rstrip()) print(s2.strip()) print(s2.lstrip()) print(s2.rstrip()) =========================================== Finding substrings: =================== index(): ======= ==> can accept the sub-string (part of the string) and return the first occurrence (index) Syntax: str-obj-name.index(sub-string) ==> by searching the sub-string from left to right (forward direction) rindex(): ======== can accept the sub-string (part of the string) and return the first occurrence (index) ==> from right to left (reverse access) Syntax: str-obj.rindex(sub-string) s = "Object Oriented" i1 = s.index('O') # 0 and 7 i2 = s.rindex('O') i3 = s.index('e') # 3, 10, 13 i4 = s.rindex('e') i5 = s.index("Orien") i6 = s.rindex("Orien") # i7 = s.index("B") # Type Error print(i1) print(i2) print(i3) print(i4) print(i5) print(i6) # print(i7) ======================================================== Website: https://www.ashokit.in/home Free Python Training 📅 Start Date : Today (04-Nov-2024) ⏰ Class Time: 08:00 PM (IST) ✍️ Zoom Link : https://bit.ly/3Yj8eXe 🔥 For Python BackupVideos (599 INR) : https://rzp.io/rzp/4YMKic7 👉 Join in Our WhatsApp Channel : https://bit.ly/49wCWje