Tách chuỗi và lưu trữ trong biến python
Đầu tiên, tôi sẽ giới thiệu cho bạn cú pháp của phương thức 7. Sau đó, bạn sẽ thấy cách sử dụng phương thức 7 có và không có đối số, sử dụng các ví dụ mã trong quá trình thực hiện Show
Đây là những gì chúng tôi sẽ đề cập Phương thức coding_journey = "I am learning to code for free with freeCodecamp!"
# split string into a list and save result into a new variable
coding_journey_split = coding_journey.split()
print(coding_journey)
print(coding_journey_split)
# check the data type of coding_journey_split by using the type() function
print(type(coding_journey_split))
# output
# I am learning to code for free with freeCodecamp!
# ['I', 'am', 'learning', 'to', 'code', 'for', 'free', 'with', 'freeCodecamp!']
# |