Hướng dẫn how do you convert a uppercase letter to a lowercase in python? - Làm thế nào để bạn chuyển đổi một chữ cái viết hoa thành chữ thường trong python?

Phương thức

string.lower()
6 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 ()

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

string.lower()
6 là:

string.lower()

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

Phương thức

string.lower()
6 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()
6 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.

Nếu không gian, hãy tăng bộ đếm tương ứng của nó và thêm nó vào một chuỗi mớiisupper(), islower(), upper(), and lower() functions in Python. These methods are built-in methods used for handling strings. Before studying them in detail let’s get a basic idea about them.

In chuỗi mới.

# 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
Input: string = 'GEEKSFORGEEKS'
Output: True

Input: string = 'GeeksforGeeks'
Output: False
2True if all characters in the string are uppercase, otherwise, returns “False”. 

  1. Input: string = 'GEEKSFORGEEKS'
    Output: True
    
    Input: string = 'GeeksforGeeks'
    Output: False
    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
    Input: string = 'GEEKSFORGEEKS'
    Output: True
    
    Input: string = 'GeeksforGeeks'
    Output: False
    5
  2. Do đó, nó không có bất kỳ đối số nào, nó sẽ trả về một lỗi nếu một tham số được truyền.
  3. Các chữ số và ký hiệu trở lại được trả về như vậy, chỉ có một chữ cái viết hoa được trả về sau khi chuyển đổi thành chữ thường.

Cú pháp thấp hơn ()

Input: string = 'GEEKSFORGEEKS'
Output: True

Input: string = 'GeeksforGeeks'
Output: False

Cú pháp của & nbsp; isupper () & nbsp;

Cú pháp: String.isupper () & nbsp; string.isupper() 

Parameters: 

  • isupper () không lấy bất kỳ tham số & nbsp;

Trả về: Đúng- Nếu tất cả các ký tự trong chuỗi là chữ hoa. Sai- Nếu chuỗi chứa 1 hoặc nhiều ký tự không tăng cấp. True- If all characters in the string are uppercase. False- If the string contains 1 or more non-uppercase characters.

Thí dụ:

Python3

# 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
# 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())

2

# 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
# 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())

4

# 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
# 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())

7

# 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
# 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())

4

Output:

True
False

Islower () trong python là gì

Trong Python, Islower () là một phương thức tích hợp được sử dụng để xử lý chuỗi. Phương thức isLower () trả về true nếu tất cả các ký tự trong chuỗi là chữ thường, nếu không, trả về FALL FALSE. & NBSP;True if all characters in the string are lowercase, otherwise, returns “False”. 

  1. Nó trả về một cách đúng sự thật cho các không gian trắng nhưng nếu chỉ có khoảng trắng trong chuỗi thì hãy trả về Sai Sai.
  2. Do đó, nó không có bất kỳ đối số nào, nó sẽ trả về một lỗi nếu một tham số được truyền.
  3. Các chữ số và ký hiệu trả về trực tiếp, nhưng nếu chuỗi chỉ chứa các chữ số và số thì sau đó trả về Sai False.

Hàm này được sử dụng để kiểm tra xem đối số có chứa bất kỳ ký tự thường nào như:

________số 8

Cú pháp của Islower ()

Cú pháp: String.islower ()string.islower()

Parameters:

  • isLower () không lấy bất kỳ tham số nào

Returns:

  • Đúng- nếu tất cả các ký tự trong chuỗi thấp hơn.
  • Sai- Nếu chuỗi chứa 1 hoặc nhiều ký tự không hạ thấp.

Thí dụ:

Python3

# 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
this should be lowercase!
th!s sh0uld b3 l0w3rcas3!
2

# 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
this should be lowercase!
th!s sh0uld b3 l0w3rcas3!
4

# 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
# 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())

7

# 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
this should be lowercase!
th!s sh0uld b3 l0w3rcas3!
4

Output:

True
False

Islower () trong python là gì

Trong Python, Islower () là một phương thức tích hợp được sử dụng để xử lý chuỗi. Phương thức isLower () trả về true nếu tất cả các ký tự trong chuỗi là chữ thường, nếu không, trả về FALL FALSE. & NBSP;

  1. Do đó, nó không có bất kỳ đối số nào, nó sẽ trả về một lỗi nếu một tham số được truyền.
  2. Các chữ số và ký hiệu trả về trực tiếp, nhưng nếu chuỗi chỉ chứa các chữ số và số thì sau đó trả về Sai False.
string.lower()
0

Hàm này được sử dụng để kiểm tra xem đối số có chứa bất kỳ ký tự thường nào như:

________số 8 string.lower()

Parameters:

  • Cú pháp của Islower ()

Cú pháp: String.islower ()It converts the given string in into lowercase and returns the string.

Examples:

Python3

# 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
# 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())

2

# 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
# 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.")
4

# 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
# 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())

7

# 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
# 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.")
4

Output:

string.lower()
1

Islower () trong python là gì

Trong Python, Islower () là một phương thức tích hợp được sử dụng để xử lý chuỗi. Phương thức isLower () trả về true nếu tất cả các ký tự trong chuỗi là chữ thường, nếu không, trả về FALL FALSE. & NBSP;

  1. Do đó, nó không có bất kỳ đối số nào, nó sẽ trả về một lỗi nếu một tham số được truyền.
  2. Các chữ số và ký hiệu trả về trực tiếp, nhưng nếu chuỗi chỉ chứa các chữ số và số thì sau đó trả về Sai False.
string.lower()
2

Hàm này được sử dụng để kiểm tra xem đối số có chứa bất kỳ ký tự thường nào như:

________số 8string.upper()

Parameters:

  • Cú pháp của Islower ()

Cú pháp: String.islower ()It converts the given string in into uppercase and returns the string.

Example:

Python3

# 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
this should be lowercase!
th!s sh0uld b3 l0w3rcas3!
2

# 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
The strings are same.
4

Cái gì thấp hơn () trong python

# 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
The strings are same.
4

Output:

string.lower()
3

Trong Python, Hạ () là một phương thức tích hợp được sử dụng để xử lý chuỗi. Phương thức thấp hơn () trả về chuỗi thấp hơn 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. & Nbsp;

Các chữ số và ký hiệu trở lại được trả về như vậy, chỉ có một chữ cái viết hoa được trả về sau khi chuyển đổi thành chữ thường.

string.lower()
4

Cú pháp thấp hơn ()

  1. Cú pháp: String.Lower ()
  2. thấp hơn () không lấy bất kỳ tham số nào
  3. Trả về: Nó chuyển đổi chuỗi đã cho thành chữ thường và trả về chuỗi.
  4. Trên () trong python là gì

Example:

Python3

Trong Python, Upper () là một phương thức tích hợp được sử dụng để xử lý chuỗi. Phương thức trên () trả về chuỗi bán dẫn từ chuỗi đã cho. Nó chuyển đổi tất cả các ký tự thường thành chữ hoa. Nếu không có ký tự viết thường tồn tại, nó sẽ trả về chuỗi gốc. & NBSP;

Các chữ số và ký hiệu trở lại được trả về như vậy, chỉ có một chữ cái viết thường được trả về sau khi chuyển đổi thành chữ hoa.

Cú pháp của trên ()

Cú pháp: String.upper ()

trên () không lấy bất kỳ tham số nào

Trả về: Nó chuyển đổi chuỗi đã cho thành chữ hoa và trả về chuỗi.

# 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
The strings are same.
7

Đếm chữ hoa, chữ thường và không gian

Đưa ra một chuỗi, nhiệm vụ là viết một chương trình Python để đếm một số chữ hoa, chữ cái chữ thường và khoảng trắng trong một trường hợp chuỗi và chuyển đổi chuỗi đã cho (chuyển đổi chữ thường thành chữ hoa và ngược lại).

Thuật toán

Đi qua ký tự chuỗi đã cho bằng ký tự lên đến chiều dài của nó và kiểm tra xem ký tự ở chữ thường hay chữ hoa bằng các phương thức tích hợp.

Nếu chữ thường, hãy tăng bộ đếm tương ứng của nó, hãy chuyển đổi nó thành chữ hoa bằng cách sử dụng hàm trên () và thêm nó vào một chuỗi mới, nếu chữ hoa, hãy tăng bộ đếm tương ứng của nó, hãy chuyển đổi nó thành chữ thường bằng hàm thấp hơn () sợi dây.

Nếu không gian, hãy tăng bộ đếm tương ứng của nó và thêm nó vào một chuỗi mới

In chuỗi mới.

# 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
Input: string = 'GEEKSFORGEEKS'
Output: True

Input: string = 'GeeksforGeeks'
Output: False
2

# 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()
31
string.lower()
32
string.lower()
33

# 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()
31
string.lower()
36
string.lower()
37

# 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()
31
string.lower()
40
string.lower()
41

# 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()
31
string.lower()
44
string.lower()
45

# 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()
31
string.lower()
48
string.lower()
33

# 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()
51

Output:

string.lower()
5