“Zeichenfolge zur Liste” Code-Antworten

Konvertieren Sie die Zeichenfolge, um Python aufzulisten

# To split the string at every character use the list() function
word = 'abc'
L = list(word)
L
# Output:
# ['a', 'b', 'c']

# To split the string at a specific character use the split() function
word = 'a,b,c'
L = word.split(',')
L
# Output:
# ['a', 'b', 'c']
SkelliBoi

Zeichenfolge zur Liste

>>> names='''
...       Apple
...       Ball
...       Cat'''
>>> names
'\n      Apple\n      Ball\n      Cat'
>>> names_list = [y for y in (x.strip() for x in names.splitlines()) if y]
>>> # if x.strip() is used to remove empty lines
>>> names_list
['Apple', 'Ball', 'Cat']
Upset Unicorn

String, um Python aufzulisten

# Python code to convert string to list
  
def Convert(string):
    li = list(string.split(" "))
    return li
  
# Driver code    
str1 = "Geeks for Geeks"
print(Convert(str1))
AVIGNAN NAG

Konvertieren Sie eine Zeichenfolge in eine Liste in Python

def dpro(string):
    convertedlist = list(string.split(" "))
    return convertedlist
  
print(dpro("this will convert to List"))
Attractive Ape

Ähnliche Antworten wie “Zeichenfolge zur Liste”

Fragen ähnlich wie “Zeichenfolge zur Liste”

Weitere verwandte Antworten zu “Zeichenfolge zur Liste” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen