String indexing in Python is easy ✂️

Описание к видео String indexing in Python is easy ✂️

#python #tutorial #course

00:00:00 string indexing
00:05:17 last 4 digits exercise
00:06:27 reverse a string exercise
00:07:06 conclusion

indexing = accessing elements of a sequence using [] (indexing operator)
[start : end : step]

credit_number = "1234-5678-9012-3456"

print(credit_number[0])
print(credit_number[0:4])
print(credit_number[:4])
print(credit_number[4:8])
print(credit_number[4:])
print(credit_number[-1])
print(credit_number[-4:])
print(credit_number[::2])
print(credit_number[::3])

EXERCISE 1
credit_number = "1234-5678-9012-3456"
last_digits = credit_number[-4:]
print(f"XXXX-XXXX-XXXX-{last_digits}")

EXERCISE 2
credit_number = "1234-5678-9012-3456"
credit_number = credit_number[::-1]
print(credit_number)

Комментарии

Информация по комментариям в разработке