1. String
Strings are seemingly simple, but can be referenced in many ways. A string is a series of characters, in Python, enclosed in single or double quotes, are strings. For example:
This mutual use of single and double quotes allows us to be more flexible in the use of strings, suitable for a variety of scenarios. For example:
Python provides a number of built-in functions to handle strings, let's look at common string handling methods:
1.1 Using built-in function methods to modify the casing of a string: Title (), Upper (), Lower ()
Call the title () method to turn the first letter of each word into uppercase and output the result as follows:
In this instance, the lowercase string is stored first in the Fird variable, and in the print () statement, the method title () appears after the Fird variable. Methods are the operations that Python can perform on the data. In Fird.title (), the period behind the Fird. Let python perform the action specified by the method title () on the variable Fird. Each method is followed by a pair of parentheses, because the method usually requires additional information to complete its work. The function title () does not require additional information, and the following parentheses are empty. Title () displays each word in an uppercase letter, changing the first letter of each word to uppercase.
Upper is to convert lowercase letters to uppercase. The code is as follows:
The output results are as follows:
Lower () is converted to lowercase letters, this and upper () function is just the opposite, you can practice it yourself, here no longer repeat.
Python data Type-string