Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

 Find length of string  Accessing individual characters/slicing  Difference between string and list.  Convert to lowercase / uppercase / titlecase / swapcase  Verify if the strings consists of alphabets/digits/upper/lower  Split string  Find substring  A string is a...

 Find length of string  Accessing individual characters/slicing  Difference between string and list.  Convert to lowercase / uppercase / titlecase / swapcase  Verify if the strings consists of alphabets/digits/upper/lower  Split string  Find substring  A string is a sequence of characters.  We can create string by enclosing characters in quotes.  Python treats single quotes the same as double quotes.  Python uses Unicode format to represent characters.  Reading and Printing a string  We can access individual characters of string using indexing.  If we try to access index out of the range or use decimal number, we will get errors.  Since there is no separate “character” type, indexing a string produces strings of length 1  We can access substrings using slicing  Joining of two or more strings into a single one is called concatenation.  The + operator does this in Python.  The * operator can be used to repeat the string for a given number of times.  Using for loop we can iterate through a string. str.isalnum() str.isalpha() str.isdigit() str.islower() str.isspace() str.isupper() str.istitle()  Write code to check if the given password is strong or not. str.lower() Convert all characters to lowercase str.upper() Convert all characters to uppercase str.swapcase() Convert uppercase to lowercase and vice versa str.title() First char of each word is changed to uppercase and others to lowercase str.capitalize() First char of the string is changed to uppercase others to lowercase  You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.  Count the number of vowels in a string. str.count(sub) Return the number of non-overlapping occurrences of substring sub. str.find(sub) Return the lowest index in the string where substring sub is found. Return -1 if sub is not found. str.index(sub) Like find(), but raise ValueError when the substring is not found. str.split(sep = None) Return a list of the words in the string, using sep as the delimiter string. S.join(list) Return a string which is the concatenation of the strings in the list. The separator between elements is S. Count number of overlapping substrings  Return a list of the words in String  Default separator is any space(space,newline,tab)  To specify any other separator, specify it explicitly.  Used to efficiently construct strings from multiple fragments.  str.join(iterable)  Return a string which is the concatenation of the strings in iterable.  The separator between elements is the string providing this method.  A TypeError will be raised if there are any non-string values in iterable.  vowels = ['a', 'e', 'i', 'o', 'u']  vowels  ['a', 'e', 'i', 'o', 'u']  s = "-".join(vowels)  s  'a-e-i-o-u'  nums = [12,23,21,43,56]  nums  [12, 23, 21, 43, 56]  s = "".join(nums)  TypeError: sequence item 0: expected str instance, int found  s = "".join(map(str , nums) )  s  '1223214356'  Replace method  An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.  Anagram Example: LISTEN SILENT BINARY BRAINY SCHOOL MASTER THE CLASSROOM CAR ARC  Given two strings, verify if they are anagram  Pangram is a sentence containing every letter of the alphabet.  Given a sentence, determine whether it is pangram, ignore case.  Pangram Examples:  The quick brown fox jumps over the lazy dog  Two driven jocks help fax my big quiz.​  Pack my box with five dozen liquor jugs.  The five boxing wizards jump quickly.  Bright vixens jump; dozy fowl quack.  Write a program to verify if the given string has all unique characters  Write a program to remove all duplicate characters from a string.

Tags

string manipulation python programming programming concepts computer science
Use Quizgecko on...
Browser
Browser