The capitalize of the string method

Source: Internet
Author: User

Describe

Python capitalize () capitalizes the first letter of a string and other letters to lowercase.

Grammar

Capitalize () method syntax:

return value

The method returns a first-letter uppercase string.

Cases
#!/usr/bin/env python#-*-coding:utf-8-*-#Author:az Ning" "Note that: 1. The first character is converted to uppercase, and the remaining characters are converted to lowercase. 2, if the first character is non-letter, the initial letter will not be converted to uppercase, will be converted to lowercase. " "Str="Abcdefghigk"str_1= Str.capitalize ()#capitalize the first digit of the string as a letterPrint(str_1) str_2="89FAFASAAAAAAASDFSF"   #if the first non-letter, the first position does not make any changes, all subsequent uppercase letters become lowercaseStr_2 =str_2.capitalize ()Print(str_2)

The results of the operation are as follows:

Abcdefghigk89fafasaaaaaaasdfsf

The capitalize of the string method

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.