I'm trying to grab every other letter from a string but i'm having some problem with print and return.
Why when i use print, the output is what i want and when i use return i only get the first letter?
string_bits(Hello) # Return string made of every other char starting with the first
def string_bits(str):
x = len(str)
for i in range(0,x,2):
print str[i]
output: H
l
o
vs
def string_bits(str):
x = len(str)
for i in range(0,x,2):
return str[i]
output: H
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…