![]() Strings are sequence of characters where each character has a unique index. Question 5Ĭan you say strings are character lists? Why? Why not? Here one operand is string and other is numeric. The operands of + operator should be both string or both numeric. 3 is not a legal string operation in Python. Which of the following is not a Python legal string operation? What is the result of following statement, if the input is 'Fun'? Out of the following operators, which ones can be used with strings in Python? Write a Python script that traverses through an input string and prints its characters in different lines - two characters per line. The split() returns always a 3-element list.įalse Type A : Short Answer Questions/Conceptual Questions Question 1 The partition() function's result is always a 3-element tuple. The find() does not raise an exception if the substring is not found. The find() and index() are similar functions. Like '+', all other arithmetic operators are also supported by strings.įunctions capitalize() and title() return the same result.įunctions partition() and split() work identically. Strings are immutable in Python, which means a string cannot be modified. Python does not support a character type a single character is treated as strings of length one. Strings have both positive and negative indexes. Question 10įunction split() divides a line of text into individual words. Question 9įunction index() raises an exception if the substring is not found. To get each word's first letter capitalized, title() function is used. 'ab'.isalpha() will return value as True. If a string contains letters and digits, function isalnum() will return true. The ord() returns the ASCII value of a given character. ![]() The in and not in are membership operators for strings (in, not in). Question 3įor strings, * operator performs replication. Question 2įor strings, + operator performs concatenation. Which of the following functions will raise an error if the given substring is not found in the string? Which of the following functions removes all leading and trailing spaces from a string? TypeError: unsupported operand type(s) for * : 'str' and 'int'Ĭhoose the correct function to get the character from ASCII number.What is the output of the following code? Which of the following functions will always return a tuple of 3 elements? ![]() Which of the following functions will return a list containing all words of the string? Which of the following functions will return the string with every 'P' replaced with a 'z'? ![]() Which of the following functions will return the string in all caps? Which of the following functions will return the first three characters of a string s? Which of the following functions will return the last three characters of a string s? Which of the following functions will return the total number of characters in a string? Which of the following is/are not legal string operators? ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |