Python DayDayUp series-string operation (1), pythondayup

Source: Internet
Author: User
Tags string methods uppercase letter

Python DayDayUp series-string operation (1), pythondayup

This document describes several common string methods.

One String method: upper (), lower (), isupper (), islower ()

The upper () and lower () Methods return a new string. The letters of the original string are converted to uppercase or lowercase letters.

Non-letter characters remain unchanged.

>>> spam  = 'Hello world!'>>> spam.upper()'HELLO WORLD!'>>> spam.lower()'hello world!'

If a string contains at least one letter, isupper () and islower (), True or False is returned Based on the upper or lower case letters (both uppercase and lowercase:

>>> Spam = 'Happy tomorrow '>>> spam. islower () False >>> spam. isupper () False >>> spam = '000000' >>> spam. islower () False >>> spam. isupper () False >>> spam = 'Happy '>>> spam. isupper () True

Binary string method isX (return value is True False ):

  • Isalpha (): returns True. The string contains only letters.
  • Isalnum (): True. The string contains only letters and numbers and is not empty.
  • Isdecimal (): True. The string contains only numeric characters and is not empty.
  • Isspace (): True. If the string contains only spaces, tabs, and line breaks, it is not empty.
  • Istitle (): True. A string can only start with an uppercase letter and is followed by a word with a lowercase letter.
>>> spam = 'hello'>>> spam.isalpha()True>>> spam.isalnum()True
# Test isdecimal () while True: x = input ('enter your age: ') if x. isdecimal (): break print ('Enter the number') # test isalnum () while True: password = input ('Enter the password: ') if password. isalnum (): break print ('password can only be numbers or letters! ')

 

  

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.