“Как разделить строку каждые 2 символа Python” Ответ

Как от разделил строку каждый четвертый eter

>>> line = '1234567890'
>>> n = 2
>>> [line[i:i+n] for i in range(0, len(line), n)]
['12', '34', '56', '78', '90']
Successful Swiftlet

Разделите строку с 2 чар на Python

a_string = "abcde"

n = 2
split_strings = [a_string[index : index + n] for index in range(0, len(a_string), n)]
Nervous Nightingale

Python разделяет каждый символ в строке

def split(word): 
    return [char for char in word]
TheAssassin

разделен на несколько символов Python

# Python3 code to demonstrate working of 
# Splitting operators in String 
# Using re.split() 
  
import re
  
# initializing string
data = "GeeksforGeeks, is_an-awesome ! website"
  
# printing original string  
print("The original string is : " + data) 
  
# Using re.split() 
# Splitting characters in String 
res = re.split(', |_|-|!', data)
  
# printing result  
print("The list after performing split functionality : " + str(res))
Condemned Corncrake

Python преобразует строки в куски

s = '1234567890'
o = []
while s:
    o.append(s[:2])
    s = s[2:]
Elated Echidna

Как разделить строку каждые 2 символа Python

def splitString(s):
	if len(s)%2 ==0:
    	num=2
        split_string= [s[i:i+num] for i in range(0, len(s), num]
        return split_string
	elif len(s)%2 !=0:
    	newstring=s+"_"
        num = 2
        split_string= [newstring[i:i+num]for i in range(0, len(newstring),num)]
        return split_string
        
        
splitString("Godwin")
splitString("wekesa")
Godwin Wabz

Ответы похожие на “Как разделить строку каждые 2 символа Python”

Вопросы похожие на “Как разделить строку каждые 2 символа Python”

Больше похожих ответов на “Как разделить строку каждые 2 символа Python” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования