Dize işlemleri

Python'da Regular Expressions

Maria Eugenia Inzaugarat

Data Scientist

Büyük/küçük harf ayarlama

my_string = "tHis Is a niCe StriNg"
  • Küçük harfe dönüştürme
print(my_string.lower())
this is a nice string
  • Büyük harfe dönüştürme
print(my_string.upper())
THIS IS A NICE STRING
Python'da Regular Expressions

 

my_string = "tHis Is a niCe StriNg"

 

  • İlk karakteri büyük yapma
print(my_string.capitalize())
This is a nice string
Python'da Regular Expressions

Bölme

my_string = "This string will be split"
  • Dizeyi alt dizeler listesine bölme
my_string.split(sep=" ", maxsplit=2)
['This', 'string', 'will be split']
my_string.rsplit(sep=" ", maxsplit=2)
['This string will', 'be', 'split']
Python'da Regular Expressions

 

my_string = "This string will be split\nin two"

print(my_string)
This string will be split
in two

Python'da Regular Expressions
  • Satır sonlarında ayırma
my_string = "This string will be split\nin two"

 

my_string.splitlines()
['This string will be split', 'in two']
Python'da Regular Expressions

Birleştirme

  • Listedeki veya başka bir yinelenebilirdeki dizeleri birleştirin

 

my_list = ["this", "would", "be", "a", "string"]
print(" ".join(my_list))
this would be a string
Python'da Regular Expressions

Karakter temizleme

  • Soldan ve sağdan karakterleri temizler: .strip()

 

my_string = " This string will be stripped\n"
my_string.strip()
'This string will be stripped'
Python'da Regular Expressions

 

my_string = " This string will be stripped\n"
  • Sağ uçtan karakterleri kaldırın
my_string.rstrip()
' This string will be stripped'
  • Sol uçtan karakterleri kaldırın
my_string.lstrip()
'This string will be stripped\n'
Python'da Regular Expressions

Hadi pratik yapalım!

Python'da Regular Expressions

Preparing Video For Download...