Python data Type-string

Source: Internet
Author: User
Tags uppercase letter

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.