Hướng dẫn python is alphabetic

In this example, we illustrate how words can be sorted lexicographically [alphabetic order].

Nội dung chính

  • Source Code
  • Kiểm tra chuỗi có phải là chữ hay không bằng phương thức isascii trong python
  • Kiểm tra chuỗi có phải là chữ hay không bằng phương thức isalpha trong python
  • Kiểm tra chuỗi có phải là chữ hoặc số bằng phương thức isalnum trong python
  • Tổng kết và thực hành

Nội dung chính

  • Source Code
  • Kiểm tra chuỗi có phải là chữ hay không bằng phương thức isascii trong python
  • Kiểm tra chuỗi có phải là chữ hay không bằng phương thức isalpha trong python
  • Kiểm tra chuỗi có phải là chữ hoặc số bằng phương thức isalnum trong python
  • Tổng kết và thực hành

Source Code

# Program to sort alphabetically the words form a string provided by the user

my_str = "Hello this Is an Example With cased letters"

# To take input from the user
#my_str = input["Enter a string: "]

# breakdown the string into a list of words
words = [word.lower[] for word in my_str.split[]]

# sort the list
words.sort[]

# display the sorted words

print["The sorted words are:"]
for word in words:
   print[word]

Output

The sorted words are:
an
cased
example
hello
is
letters
this
with

Note: To test the program, change the value of my_str.

In this program, we store the string to be sorted in my_str. Using the split[] method the string is converted into a list of words. The split[] method splits the string at whitespaces.

The list of words is then sorted using the sort[] method, and all the words are displayed.

Bài viết liên quan

Hãy chia sẻ và cùng lan tỏa kiến thức lập trình Nhật Bản tại Việt Nam!

HOME>> python cơ bản - lập trình python cho người mới bắt đầu>>09. chuỗi trong python

Bài sau
Kiểm tra chuỗi có phải là số hay không trong python
Bài tiếp
Tìm ký tự trong chuỗi python
  • Bài viết mới nhất
  • Làm tròn số trong JavaScript [Math.round, Math.ceil, Math.floor] tháng 7 1, 2022
  • Số mũ trong JavaScript [Math.pow, Math.exp] tháng 7 1, 2022
  • Math.max và Math.min trong JavaScript tháng 7 1, 2022
  • Math.random trong JavaScript tháng 7 1, 2022
  • throw trong JavaScript và cách trả về ngoại lệ tuỳ ý tháng 7 1, 2022
  • Các ngoại lệ trong JavaScript và cách xử lý tương ứng tháng 7 1, 2022
  • try...catch trong JavaScript và cách xử lý ngoại lệ tháng 7 1, 2022
  • Xử lý ngoại lệ của hàm xử lý mô tả trong khối try tháng 7 1, 2022
if[typeof ez_ad_units != 'undefined']{ez_ad_units.push[[[300,250],'laptrinhcanban_com-leader-1','ezslot_15',560,'0','0']]};if[typeof __ez_fad_position != 'undefined']{__ez_fad_position['div-gpt-ad-laptrinhcanban_com-leader-1-0']};

Profile

Bài Viết Liên Quan

Toplist mới

Bài mới nhất

Chủ Đề