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

9 lines
212 B
Python
Raw Normal View History

2019-11-18 14:44:36 +01:00
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'))