Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_alx_pcz
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
kurs_alx_pcz
Commits
65f9b77d
Commit
65f9b77d
authored
Nov 17, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
operacje klasy str
parent
ae1a29a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
operacje_str.py
dzien3/teoria/operacje_str.py
+86
-0
No files found.
dzien3/teoria/operacje_str.py
0 → 100644
View file @
65f9b77d
napis
=
'Ala ma kota'
print
(
napis
)
print
(
len
(
napis
))
for
znak
in
napis
:
print
(
'Kolejny znak:'
,
znak
)
print
()
print
(
'Typ napisu:'
,
type
(
napis
))
print
(
'Typ znaku:'
,
type
(
napis
[
4
]))
print
(
'znak:'
,
napis
[
4
])
# numeracja od 0
print
(
'fragment:'
,
napis
[
4
:
6
])
# zakres lewostronnie domknięty
# Zawartości napisu nie da się zmienić, to nie są tablice takie jak w C. str is immutable
# napis[7] = 'K'
print
()
if
'm'
in
napis
:
print
(
'Jest literka m'
)
else
:
print
(
'Nie ma literki m'
)
# Dla napisów operator in sprawdza czy napis jest fragmentem dużego napisu (a nie tylko czy litera jest elementem)
if
'kot'
in
napis
:
print
(
'kot obecny'
)
else
:
print
(
'nie ma kota'
)
print
(
'kot jest na pozycji'
,
napis
.
index
(
'kot'
))
print
(
'kot jest na pozycji'
,
napis
.
find
(
'kot'
))
# Gdy nie znajdą: index wyrzuca wyjątek, a find zwraca -1
#ERR print('pies jest na pozycji', napis.index('pies'))
print
(
'pies jest na pozycji'
,
napis
.
find
(
'pies'
))
print
()
# Napisy można dodawać - wynikiem jest nowy napis
nowy
=
napis
+
' oraz psa'
print
(
'nowy napis:'
,
nowy
)
print
(
'stary napis:'
,
napis
)
# Napisy można mnożyć przez liczbę całkowitą - oznacza powtózenie treści
print
(
'Ala ma kota. '
*
10
)
print
()
napis
=
'Ala ma kota, a Ola ma psa. Pomagamy zwierzakom.'
print
(
napis
)
print
(
napis
.
replace
(
'ma'
,
'posiada'
))
napis
=
' Ala ma kota, a Ola ma psa. '
print
(
napis
.
replace
(
' '
,
'_'
))
print
()
print
(
'upper:'
,
napis
.
upper
())
print
(
'lower:'
,
napis
.
lower
())
print
(
'trip:'
,
napis
.
strip
())
print
(
'capitalize:'
,
'abcd efg opr'
.
capitalize
())
print
(
'title: '
,
'abcd efg opr'
.
title
())
print
()
print
(
napis
.
split
())
print
(
napis
.
split
(
','
))
lista
=
[
'Ala'
,
'Ola'
,
'Ela'
]
napis
=
';'
.
join
(
lista
)
print
(
napis
)
print
(
'Witamy osoby '
+
' oraz '
.
join
(
lista
)
+
"."
)
print
()
litera
=
'A'
cyfra
=
'0'
napis1
=
'AbcDĘ'
napis2
=
'Abc ,!@#$ '
napis3
=
' '
# gdy napis zawiera wyłącznie litery (ale także innych alfabetów), to isalpha zwraca True
# gdy jest pusty lub zawiera chociaż jeden znak nibędący literą, to zwraca False
print
(
litera
.
isalpha
())
print
(
cyfra
.
isalpha
())
print
(
napis1
.
isalpha
())
print
(
napis2
.
isalpha
())
print
(
napis3
.
isalpha
())
print
(
napis3
.
isspace
())
# są też inne metody .is_____
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment