Which method is used to convert a string to uppercase in Python?
Strings — Important Questions
SUMMARY: This chapter focuses on the concept of strings in Python, including their properties and manipulation techniques.
KEY TOPICS: string definition, string indexing, string slicing, string methods, string concatenation, string immutability, escape sequences, string formatting, string comparison, string operations
The output of "Hello"[1:4] is:
Check answerHide answer
Which method is used to find the length of a string?
Check answerHide answer
The output of "abc" * 3 is:
Check answerHide answer
Strings in Python are:
Check answerHide answer
What is the result of the expression 'Python' + 'Programming'?
Check answerHide answer
Which of the following escape sequences represents a newline in a string?
Check answerHide answer
What will be the output of 'Hello, World!'[7:]?
Check answerHide answer
Which method would you use to replace 'cat' with 'dog' in the string 'The cat is here'?
Check answerHide answer
What is the output of 'abc'[::-1]?
Check answerHide answer
Which of the following statements about strings in Python is true?
Check answerHide answer
What will be the result of 'A' < 'B'?
Check answerHide answer
Which of the following methods can be used to convert the first character of a string to uppercase?
Check answerHide answer
What does the method 'strip()' do when applied to a string?
Check answerHide answer
In Python, which of the following is a valid way to format a string?
Check answerHide answer
Differentiate between strip() lstrip() and rstrip() string methods.
Write Python code to count the number of vowels in a string.
Explain the use of split() and join() string methods with one example each.
What is string slicing? Give one example.
Differentiate between find() and index() string methods.
What is string immutability in Python? Provide an example to illustrate your answer.
View sample solutionHide solution
Explain how string concatenation works in Python. Provide a code example.
View sample solutionHide solution
What are escape sequences in Python strings? Give two examples.
View sample solutionHide solution
Describe the purpose of the format() method in Python strings. Provide an example.
View sample solutionHide solution
What is string indexing? How would you access the first character of a string in Python?
View sample solutionHide solution
Differentiate between list and string in Python in tabular form.
Compare find() and index() string methods with the help of a table.
Differentiate between strip() lstrip() and rstrip() in tabular form.
Write a Python program to check if a given string is a palindrome ignoring case.
Discuss any five built-in string methods with one example each.
Write a Python program to count the frequency of each character in a string.
Assertion (A): Strings are immutable in Python.
Reason (R): Once created their characters cannot be changed in place.
Show explanationHide explanation
Assertion (A): Negative indexing in strings starts from the end.
Reason (R): The last character has index -1.
Show explanationHide explanation
Assertion (A): The * operator can be used to repeat a string.
Reason (R): It is overloaded for sequences in Python.
Show explanationHide explanation
Assertion (A): Strings can be enclosed in single double or triple quotes.
Reason (R): Triple quotes allow multi-line strings.
Show explanationHide explanation
Assertion (A): The 'in' operator checks substring membership.
Reason (R): It returns True if the substring is found.
Show explanationHide explanation
Assertion (A): String slicing can be used to extract a substring from a string.
Reason (R): String slicing uses the syntax string[start:end] to obtain a portion of the string.
Show explanationHide explanation
Assertion (A): The method str.upper() converts all characters in a string to lowercase.
Reason (R): The str.upper() method is designed to convert all characters in a string to uppercase.
Show explanationHide explanation
Assertion (A): Escape sequences in strings are used to represent special characters.
Reason (R): Escape sequences begin with a backslash and allow for the inclusion of characters that are otherwise difficult to represent.
Show explanationHide explanation
Statement 1: Strings can be sliced using the [start:stop:step] syntax.
Statement 2: Negative indices count from the end.
Show answerHide answer
Statement 1: String concatenation is done using the + operator.
Statement 2: String repetition uses the * operator.
Show answerHide answer
Statement 1: len() returns the length of a string.
Statement 2: It works on any sequence type.
Show answerHide answer
Statement 1: The split() method breaks a string into a list.
Statement 2: The join() method joins list items into a string.
Show answerHide answer
Statement 1: Escape sequences begin with a backslash.
Statement 2: Examples include \\n for newline and \\t for tab.
Show answerHide answer
Statement 1: String indexing in Python starts from 1.
Statement 2: The first character of a string can be accessed using index 0.
Show answerHide answer
Statement 1: Strings in Python are mutable, allowing modification of individual characters.
Statement 2: The string 'hello' can be formatted using f-strings in Python.
Show answerHide answer
Statement 1: The method upper() converts all characters in a string to lowercase.
Statement 2: The method lower() converts all characters in a string to uppercase.
Show answerHide answer
-
Which Python function returns the length of a string?AlenBlengthCcountDsize
-
Strings in Python are:AMutableBImmutableCOrdered listDRandom list
-
Write the complete Python program to count vowels and explain how it handles uppercase letters.
Show answersHide answers
-
What does it mean that strings are immutable in Python?
-
What will be the output of the expression 'Hello'[1:4]?AHelloBellCHeDlo
-
What is the index of the first character in a string?A1B0C2D-1
Show answersHide answers
-
What is the result of concatenating 'Hello' and 'World' with a space in between?AHelloWorldBHello WorldCHello_WorldDHello+World
-
Explain the purpose of the .upper() method in Python strings.
-
Does the .lower() method modify the original string?AYesBNoCOnly if it is a variableDIt depends on the string length
Show answersHide answers
-
How does Python determine the order of strings during comparison?ABy length of the stringsBBy ASCII values of charactersCBy the first character onlyDBy the last character only
-
What will be the result of comparing 'Apple' and 'apple'?AEqualBNot equalCGreater thanDLess than
-
What operator is used to check for equality between two strings?
Show answersHide answers
Predict the output of each string operation.
| s = 'Hello World' | Result |
|---|---|
| len(s) | ? |
| s.upper() | ? |
| s[0:5] | ? |
| s[-1] | ? |
| s.split() | ? |
| 'World' in s | ? |
Study the table of common string methods and answer:
| Method | Use | Example output |
|---|---|---|
| upper() | Uppercase | 'hello'.upper() = HELLO |
| lower() | Lowercase | 'Hello'.lower() = hello |
| strip() | Remove whitespace | ' ab '.strip() = ab |
| split() | Split into list | 'a b c'.split() = ['a','b','c'] |
| replace() | Replace substring | 'cat'.replace('c','b') = bat |
-
Which method converts a string to uppercase?Aupper()Buppercase()CtoUpper()Dup()
-
Which method splits a string into a list?AjoinBsplitCbreakDdivide
-
Discuss any five string methods with one example each.
Show answersHide answers
What is the length of the string 'Python Programming' as shown in the table?
| String | Length |
|---|---|
| Python Programming | 18 |
| Java Programming | 16 |
Study the following data and answer the questions below:
| String | Uppercase | Lowercase |
|---|---|---|
| hello | HELLO | hello |
| WORLD | WORLD | world |
| Python | PYTHON | python |
-
What is the uppercase form of the string 'hello'?
-
Which string has the same uppercase and lowercase representation?
Show answersHide answers
Study the string indexing diagram and answer:
-
For s = 'PYTHON' what is s[-1]?APBYCNDO
-
For s = 'PYTHON' what is s[0:3]?APYTBPYTHCYTHDONHT
-
Explain string indexing and slicing with examples.
Show answersHide answers
Based on the given diagram of string slicing in Python, answer the following:
-
What does the slice 'string[1:4]' return?AstrBtriCingDing
-
Explain the output of 'string[:3]'.
Show answersHide answers
Based on the given flowchart of string methods in Python, answer the following:
-
Which method would you use to convert a string to lowercase?AUppercaseBLowercaseCStripDReplace
-
What does the 'strip' method do?
Show answersHide answers
Based on the given diagram showing string concatenation, answer the following:
-
What is the result of concatenating 'Hello' and 'World'?AHelloWorldBHello WorldCHello+WorldDHello, World!
-
Describe how string concatenation is performed in Python.
Show answersHide answers
Make a full Computer Science paper on Strings.
Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.
Generate your paper — free