Hướng dẫn how do you convert uppercase letters to lowercase in python? - làm thế nào để bạn chuyển đổi chữ hoa thành chữ thường trong python?

Phương thức

string.lower()
1 chuyển đổi tất cả các ký tự chữ hoa trong một chuỗi thành các ký tự thường và trả về nó.

Thí dụ

message = 'PYTHON IS FUN'

# convert message to lowercase print(message.lower())

# Output: python is fun


Cú pháp của chuỗi thấp hơn ()

Phương pháp cú pháp của phương pháp

string.lower()
1 là:

string.lower()

HẤP DẪN () tham số ()

Phương thức

string.lower()
1 không lấy bất kỳ tham số nào.


thấp hơn () giá trị trả về

Phương thức

string.lower()
1 Trả về chuỗi chữ thường từ chuỗi đã cho. Nó chuyển đổi tất cả các ký tự chữ hoa thành chữ thường.

Nếu không có ký tự chữ hoa tồn tại, nó sẽ trả về chuỗi gốc.


Ví dụ 1: Chuyển đổi chuỗi thành chữ thường

# example string
string = "THIS SHOULD BE LOWERCASE!"

print(string.lower())

# string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

print(string.lower())

Đầu ra

this should be lowercase!
th!s sh0uld b3 l0w3rcas3!

Ví dụ 2: Làm thế nào thấp hơn () được sử dụng trong một chương trình?

# first string
firstString = "PYTHON IS AWESOME!"

# second string
secondString = "PyThOn Is AwEsOmE!"

if(firstString.lower() == secondString.lower()):

print("The strings are same.") else: print("The strings are not same.")

Đầu ra

The strings are same.

Ví dụ 2: Làm thế nào thấp hơn () được sử dụng trong một chương trình? If you want to convert to uppercase string, use upper(). You can also use swapcase() to swap between lowercase to uppercase.

Làm thế nào để bạn chuyển đổi thành chữ hoa trong Python?

Phương thức Python String Upper () Phương thức trên () Phương thức trả về một chuỗi trong đó tất cả các ký tự ở trường hợp trên.

Xem thảo luận

  • Cải thiện bài viết
  • Lưu bài viết
  • Làm thế nào để bạn chuyển đổi thành chữ hoa trong Python?

    Phương thức Python String Upper () Phương thức trên () Phương thức trả về một chuỗi trong đó tất cả các ký tự ở trường hợp trên.

    Xem thảo luận

    Cải thiện bài viếtlower() method converts all uppercase characters in a string into lowercase characters and returns it. In this article, we will cover how to convert uppercase to lowercase in Python. 

    Ở đây chúng tôi cũng sẽ bao gồm chức năng Caseprint và Swapcase để hạ thấp chuỗi của chúng tôi.casefold and swapcase function to lower our string.

    Chức năng cú pháp của .lower ()

    Cú pháp: String.Lower () string.lower()

    Tham số: phương thức thấp hơn () không có bất kỳ tham số nào. & Nbsp; The lower() method doesn’t take any parameters. 

    Trả về: Trả về chuỗi chữ thường của chuỗi đã cho Returns a lowercase string of the given string

    Ví dụ 1: Hàm () Hàm để chuyển đổi ký tự & nbsp;

    Chuỗi chỉ có ký tự chữ cái & nbsp;

    Python3

    string.lower()
    5
    string.lower()
    6
    string.lower()
    7

    string.lower()
    8
    string.lower()
    9
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    0
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    1

    string.lower()
    8
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    3

    string.lower()
    8
    string.lower()
    9
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    6
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    1

    string.lower()
    8
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    9

    Output:  

    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks

    Ví dụ 2: & nbsp; Hạ () hàm để chuyển đổi chuỗi thành lower_case 2:  lower() function to convert string to lower_case

    Chuỗi có ký tự chữ và số & nbsp;

    Python3

    string.lower()
    5
    string.lower()
    6
    this should be lowercase!
    th!s sh0uld b3 l0w3rcas3!
    2

    string.lower()
    8
    string.lower()
    9
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    0
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    1

    string.lower()
    8
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    3

    string.lower()
    8
    string.lower()
    9
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    6
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    1

    string.lower()
    8
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    9

    Output:  

    Original String:
    G3Ek5 F0R gE3K5
    
    Converted String:
    g3ek5 f0r ge3k5

    Ví dụ 3: So sánh các chuỗi bằng phương pháp thấp hơn ()

    Một trong những ứng dụng phổ biến của phương thức thấp hơn () là kiểm tra xem hai chuỗi có giống nhau hay không.

    Python3

    # first string
    firstString = "PYTHON IS AWESOME!"
    
    # second string
    secondString = "PyThOn Is AwEsOmE!"
    
    

    if(firstString.lower() == secondString.lower()):

    print("The strings are same.") else: print("The strings are not same.")
    5
    string.lower()
    6
    # first string
    firstString = "PYTHON IS AWESOME!"
    
    # second string
    secondString = "PyThOn Is AwEsOmE!"
    
    

    if(firstString.lower() == secondString.lower()):

    print("The strings are same.") else: print("The strings are not same.")
    7

    # first string
    firstString = "PYTHON IS AWESOME!"
    
    # second string
    secondString = "PyThOn Is AwEsOmE!"
    
    

    if(firstString.lower() == secondString.lower()):

    print("The strings are same.") else: print("The strings are not same.")
    8
    # first string
    firstString = "PYTHON IS AWESOME!"
    
    # second string
    secondString = "PyThOn Is AwEsOmE!"
    
    

    if(firstString.lower() == secondString.lower()):

    print("The strings are same.") else: print("The strings are not same.")
    9
    string.lower()
    6
    string.lower()
    6
    The strings are same.
    2

    The strings are same.
    3
    string.lower()
    8
    string.lower()
    9
    The strings are same.
    6
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    1

    The strings are same.
    8
    The strings are same.
    9

    The strings are same.
    3
    string.lower()
    8
    string.lower()
    9
    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks
    3
    # example string
    string = "THIS SHOULD BE LOWERCASE!"
    

    print(string.lower())

    # string with numbers # all alphabets should be lowercase string = "Th!s Sh0uLd B3 L0w3rCas3!"

    print(string.lower())

    1

    Output:  

    Strings are same

    Ví dụ 4: Hàm SWAPCASE () để chuyển đổi chuỗi thành Lower_case() function to convert string to lower_case

    Chuyển đổi chữ hoa thành chữ thường trong Python bằng hàm hoán đổi.swapcase function.

    Python3

    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks
    5
    string.lower()
    6
    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks
    7

    string.lower()
    8
    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks
    9

    Output:

    geeksforgeeks

    Ví dụ 5: hàm caseprint () để chuyển đổi chuỗi thành lower_case() function to convert string to lower_case

    Chuyển đổi chữ hoa thành chữ thường trong Python bằng hàm chữ hoa case.casefold function.

    Python3

    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks
    5
    string.lower()
    6
    Original String:
    GeEks FOR geeKS
    
    Converted string:
    geeks for geeks
    7

    string.lower()
    8
    Original String:
    G3Ek5 F0R gE3K5
    
    Converted String:
    g3ek5 f0r ge3k5
    4

    Output:

    geeksforgeeks

    Làm thế nào để bạn chuyển đổi chữ hoa sang chữ thường?

    Steps:..
    Lấy một chuỗi của bất kỳ độ dài nào và tính độ dài của nó ..
    Quét ký tự chuỗi theo ký tự và tiếp tục kiểm tra chỉ mục.Nếu một ký tự trong một chỉ mục ở trường hợp thường
    In chuỗi cuối cùng ..

    Làm thế nào để bạn thay đổi chữ cái trong Python?

    Hãy xem nó trong hành động:..
    Hạ () điều này tương tự như trước: nó chuyển đổi một chuỗi thành các ký tự thường.....
    Viết hoa () Hàm này chỉ chuyển đổi ký tự đầu tiên của chuỗi thành chữ hoa và chuyển đổi tất cả các ký tự còn lại thành chữ thường:.
    Tiêu đề() ... .
    swapcase().

    Làm thế nào để bạn chuyển đổi thành chữ hoa trong Python?

    Phương thức Python String Upper () Phương thức trên () Phương thức trả về một chuỗi trong đó tất cả các ký tự ở trường hợp trên.upper() Method The upper() method returns a string where all characters are in upper case.