String'ler

Python'da Veri Tipleri

Jason Myers

Instructor

Biçimlendirilmiş string oluşturma

  • f-string'ler (biçimlendirilmiş string değişmezleri) - f""
cookie_name = "Anzac"
cookie_price = "$1.99"

print(f"Each { cookie_name } cookie costs { cookie_price }.")
"Each Anzac cookie costs $1.99."
Python'da Veri Tipleri

Stringlerle birleştirme

  • "".join(), üzerinde çağrıldığı string'i yineleyiciyi birleştirmek için kullanır
child_ages = ["3", "4", "7", "8"]

print(", ".join(child_ages))
"3, 4, 7, 8"
print(f"The children are ages {','.join(child_ages[0:3])}, and {child_ages[-1]}.")
"The children are ages 3, 4, 7, and 8."
Python'da Veri Tipleri

Bir string'in bölümlerini eşleştirme

  • .startswith() ve .endswith() bir string'in belirli bir karakterle ya da string'le başlayıp bitmediğini söyler
boy_names = ["Mohamed", "Youssef", "Ahmed"]
print([name for name in boy_names if name.startswith('A')])
["Ahmed"]
  • Dikkat: Bunlar ve çoğu string işlevi büyük/küçük harfe duyarlıdır.
Python'da Veri Tipleri

String'lerde arama

  • in işleci, string gibi yinelenebilir bir tipte bir değeri arar.
"long" in "Life is a long lesson in humility."
True
"life" in "Life is a long lesson in humility."
False
Python'da Veri Tipleri

Büyük/küçük harfe duyarsız bir yaklaşım

  • .lower() metodu küçük harfli bir string döndürür
"life" in "Life is a long lesson in humility.".lower()
True
Python'da Veri Tipleri

Hadi pratik yapalım!

Python'da Veri Tipleri

Preparing Video For Download...