
6-ameliy Python
.pdf
6-ámeliy jumıs
Python programmalastırıw tilinde tekstler (qatarlar)
1.Tekstlerdi jaratıw:
#Tek qatarlı tekstler tekst1 = "Sálem, Python!" tekst2 = 'Sálem, dúnya!'
#Kóp qatarlı tekstler tekst3 = """Bul kóp qatarlı
tekst"""
tekst4 = '''Bul da kóp qatarlı tekst'''
2. Tekstlerdi indekslew hám kesip alıw (slicing):
tekst = "Python" |
|
print(tekst[0]) |
# 'P' |
print(tekst[-1]) |
# 'n' |
print(tekst[0:2]) |
# 'Py' |
print(tekst[2:]) |
# 'thon' |
print(tekst[:3]) |
# 'Pyt' |
print(tekst[::2]) |
# 'Pto' |
|
|
3.Tekstlerdi formatlaw:
#f-string
atı = "Ayjan" jası = 20
print(f"Onıń atı {atı}, jası {jası}")
# format() metodı
print("Onıń atı {}, jası {}".format(atı, jası))
# % operatorı
print("Onıń atı %s, jası %d" % (atı, jası))
4. String metodları:
tekst = "python programmalastırıw tili"
# Úlken-kishi háripler |
|
|
|
|
print(tekst.upper()) |
# PYTHON PROGRAMMALASTIRIW TILI |
|||
print(tekst.lower()) |
# |
python |
programmalastırıw |
tili |
print(tekst.title()) |
# |
Python |
Programmalastırıw |
Tili |
print(tekst.capitalize()) # Python programmalastırıw tili
# Izlew hám almaslırıw |
|
print(tekst.find('prog')) |
# 7 |
print(tekst.replace('python', 'Java')) # Java programmalastırıw tili
# Tekseriwshi metodlar |
|
|
print("123".isdigit()) |
# True |
|
print("abc".isalpha()) |
# |
True |
print("Abc123".isalnum()) |
# |
True |

print(" ".isspace()) |
|
# True |
|
|
|
# Bóliw hám biriktiriw |
|
|
|
|
|
sózler = tekst.split() |
|
# ['python', 'programmalastırıw', 'tili'] |
|||
print(" ".join(sózler)) |
# python programmalastırıw tili |
||||
# Probellerdi alıp taslaw |
|
|
|
||
tekst2 = " |
python |
" |
|
|
|
print(tekst2.strip()) |
|
# "python" |
|
||
print(tekst2.lstrip()) |
|
# "python |
" |
||
print(tekst2.rstrip()) |
|
# " |
python" |
5. Tekstlerdi salıstırıw:
tekst1 = "alma" tekst2 = "almurt"
print(tekst1 == tekst2) |
# False |
|||
print(tekst1 < |
tekst2) |
# True |
||
print(tekst1 |
> |
tekst2) |
# |
False |
print("alma" |
in tekst2) |
# |
True |
|
|
|
|
|
|
6. Tekstlerdi qosıw (konkatenaciya):
atı = "Gúljamal"
familiyası = "Berdimuratova"
tolıq_atı = atı + " " + familiyası print(tolıq_atı) # Gúljamal Berdimuratova
# Tekstti qaytalaw print("Ha" * 3) # HaHaHa
Ámeliy tapsırma:
Tómendegi kodtı orınlap kóriń hám nátiyjelerin túsindirip beriń:
# Paydalanıwshı menen islesiw tekst = input("Tekst kiritiń: ")
print("\nTekst haqqında maǵlıwmat:") print(f"Uzınlıǵı: {len(tekst)}") print(f"Sózler sanı: {len(tekst.split())}")
print(f"Úlken háripler menen: {tekst.upper()}") print(f"Kishi háripler menen: {tekst.lower()}") print(f"Hár sózdiń bas hárpi úlken: {tekst.title()}")
# Belgli bir sózdi izlew
izlew_sóz = input("\nİzlew ushın sóz kiritiń: ") if izlew_sóz in tekst.lower():
print(f"'{izlew_sóz}' sózi tekstte bar")
print(f"Onıń pozitsiyası: {tekst.lower().find(izlew_sóz)}") else:
print(f"'{izlew_sóz}' sózi tekstte joq")
#Tekstti taza formatta kórsetiw taza_tekst = " ".join(tekst.split())
print(f"\nTaza formatlanǵan tekst: {taza_tekst}")
#Tekstti teris qaray jazıw
terisi = tekst[::-1] print(f"\nTerisi: {terisi}")

Qosımsha ámeliy wazıypa:
1.Berilgen teksttiń palindrom ekenin tekseriw programmasın jazıń
2.Teksttegi háriplerdiń sanın esaplaw programmasın jazıń
3.Teksttegi dawıslı hám dawıssız háriplerdi ajıratıw programmasın jazıń
Mısalı, palindromdi tekseriw ushın programa:
def palindrom_tekser(tekst):
# Tekstti tazalaw (tek háripler qalıwı ushın)
taza_tekst = ''.join(c.lower() for c in tekst if c.isalnum())
# Palindrom ekenin tekeriw
return taza_tekst == taza_tekst[::-1]
# Testlew
test_tekst = input("Tekst kiritiń: ") if palindrom_tekser(test_tekst):
print("Bul tekst palindrom") else:
print("Bul tekst palindrom emes")
TEST JUMÍSÍ
1. Tómendegi kodtıń nátiyjesin anıqlań:
tekst = "Python" print(tekst[1:4])
a)"Pyt"
b)"yth"
c)"ytho"
d)"hon"
2.String metodlarınan qaysısı tekstti úlken háriplerge ózgertedi?
a)capitalize()
b)title()
c)upper()
d)bigger()
3.Tómendegi kodtıń nátiyjesin anıqlań:
tekst = "sálem dúnya" print(tekst.title())
a)"SÁLEM DÚNYA"
b)"Sálem Dúnya"
c)"Sálem dúnya"
d)"sálem dúnya"
4.Tekstlerdi birlestiriw (konkatenaciya) ushın qaysı operator qollanıladı?
a)&
b).
c)+
d)*
5.Tómendegi kodtıń nátiyjesin anıqlań:

tekst = "Python" print(tekst[::-1])
a)"Python"
b)"nohtyP"
c)"Py"
d)"on"
6.strip() metodı neni orınlaydı?
a)Tekstti úlken háriplerge ózgertedi
b)Teksttiń bas hám aqırındaǵı probellerin alıp taslaydı
c)Tekstti bóleklerge bóledi
d)Tekstti kishi háriplerge ózgertedi
7.Tómendegi kodtıń nátiyjesin anıqlań:
tekst = "alma, almurt, erik" print(tekst.split(", "))
a)["alma almurt erik"]
b)"alma, almurt, erik"
c)["alma", "almurt", "erik"]
d)"almaalmurterik"
8.f-string formatlaw usılında qaysı sintaksis qollanıladı?
a)"Atı: %s" % atı
b)"Atı: {}".format(atı)
c)f"Atı: {atı}"
d)"Atı: " + atı
9.Tómendegi kodta qanday qátelik bar?
tekst = "Python" tekst[0] = "J"
a)Sintaksis qátesi
b)String ózgermeytuǵın (immutable) bolǵanı ushın qátelik beredi
c)Indeks qátesi
d)Qátelik joq
10.Teksttiń uzınlıǵın tabıw ushın qaysı funktsiya qollanıladı?
a)size()
b)length()
c)len()
d)count()
Durıs juwaplar:
1.b
2.c
3.b
4.c
5.b
6.b
7.c
8.c
9.b
10.c
Qosımsha túsindiriw:
1.tekst[1:4] - 1-indeksten 4-indekske shekem (4 kirmeydi) elementlerdi aladı
2.upper() metodı tekstti tolıǵı menen úlken háriplerge ózgertedi
3.title() metodı hár sózdiń bas háribin úlken hárip penen jazadı
4.
ooperatorı tekstlerdi birlestiriw ushın qollanıladı
5.[::-1] - tekstti aqırınan basına qaray oqıydı (terisi)
6.strip() metodı teksttiń bas hám aqırındaǵı artıqsha probellerin alıp taslaydı
7.split() metodı tekstti berilgen ajıratıwshı boyınsha dizimge bóledi
8.f-string - Python 3.6+ versiyalarında qollanılatuǵın zamanagóy formatlaw usılı
9.String immutable bolǵanı ushın onıń elementlerin tikkeley ózgertiw múmkin emes
10.len() funktsiyası teksttiń uzınlıǵın qaytaradı