programming-examples/python/_Basics/Python program to get a string made of the first 2 and the last 2 chars from a given a string.py
2019-11-15 12:59:38 +01:00

9 lines
212 B
Python

def string_both_ends(str):
if len(str) < 2:
return ''
return str[0:2] + str[-2:]
print(string_both_ends('w3resource'))
print(string_both_ends('w3'))
print(string_both_ends('w'))