Created by Aparna Dhirde
over 4 years ago
|
||
Question | Answer |
Sequence data types in Python | Strings, Lists and Tuples |
Strings | String is a sequence which is made up of one or more UNICODE characters. Here the character can be a letter, digit, whitespace or any other symbol. A string can be created by enclosing one or more characters in single, double or triple quote. |
String is Immutable | It means that the contents of the string cannot be changed after it has been created. |
String Operations | Concatenation,Repetition,Membership and Slicing |
Concatenation | to join two strings using concatenation operator plus which is denoted by symbol +. |
Repetition | to repeat the given string using repetition operator which is denoted by symbol *. |
Membership | Python has two membership operators 'in' and 'not in'. The 'in' operator takes two strings and returns True if the first string appears as a substring in the second string, otherwise it returns False. |
Slicing | to access some part of a string or substring, |
Built-in Functions | functions whose functionality is pre-defined in Python. |
len() | Returns the length of the given string |
title() | Returns the string with first letter of every word in the string in uppercase and rest in lowercase |
lower() | Returns the string with all uppercase letters converted to lowercase |
upper() | Returns the string with all lowercase letters converted to uppercase |
count(str, start, end) | Returns number of times substring str occurs in the given string. If we do not give start index and end index then searching starts from index 0 and ends at length of the string |
find(str,start,end) | Returns the first occurrence of index of substring str occurring in the given string. If we do not give start and end then searching starts from index 0 and ends at length of the string. If the substring is not present in the given string, then the function returns -1 |
endswith() | Returns True if the given string ends with the supplied substring otherwise returns False |
startswith() | Returns True if the given string starts with the supplied substring otherwise returns False |
isalnum() | Returns True if characters of the given string are either alphabets or numeric. If whitespace or special symbols are part of the given string or the string is empty it returns False |
islower() | Returns True if the string is non-empty and has all lowercase alphabets |
isupper() | Returns True if the string is non-empty and has all uppercase alphabets |
isspace() | Returns True if the string is non-empty and all characters are white spaces (blank, tab, newline, carriage return) |
istitle() | Returns True if the string is non-empty and title case, i.e., the first letter of every word in the string in uppercase and rest in lowercase |
lstrip() | Returns the string after removing the spaces only on the left of the string |
rstrip() | Returns the string after removing the spaces only on the right of the string |
strip() | Returns the string after removing the spaces both on the left and the right of the string |
replace(oldstr,newstr) | Replaces all occurrences of old string with the new string |
join() | Returns a string in which the characters in the string have been joined by a separator |
split() | Returns a list of words delimited by the specified substring. If no delimiter is given then words are separated by space. |
Want to create your own Flashcards for free with GoConqr? Learn more.