Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
fac38b7c
Kaydet (Commit)
fac38b7c
authored
Nis 07, 1991
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added join() and joinfields() functions.
Fixed center(). Rewrote ljust() and rjust().
üst
2d844d1d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
18 deletions
+54
-18
string.py
Lib/string.py
+27
-9
stringold.py
Lib/stringold.py
+27
-9
No files found.
Lib/string.py
Dosyayı görüntüle @
fac38b7c
...
...
@@ -79,6 +79,20 @@ def splitfields(s, sep):
res
.
append
(
s
[
i
:])
return
res
# Join words with spaces between them
def
join
(
words
):
res
=
''
for
w
in
words
:
res
=
res
+
(
' '
+
w
)
return
res
[
1
:]
# Join fields with separator
def
joinfields
(
words
,
sep
):
res
=
''
for
w
in
words
:
res
=
res
+
(
sep
+
w
)
return
res
[
len
(
sep
):]
# Find substring
index_error
=
'substring not found in string.index'
def
index
(
s
,
sub
):
...
...
@@ -99,21 +113,25 @@ def atoi(str):
# Left-justify a string
def
ljust
(
s
,
width
):
n
=
len
(
s
)
if
n
>=
width
:
return
s
return
s
+
' '
*
(
width
-
n
)
n
=
width
-
len
(
s
)
if
n
<=
0
:
return
s
return
s
+
' '
*
n
# Right-justify a string
def
rjust
(
s
,
width
):
n
=
len
(
s
)
if
n
>=
width
:
return
s
return
' '
*
(
width
-
n
)
+
s
n
=
width
-
len
(
s
)
if
n
<=
0
:
return
s
return
' '
*
n
+
s
# Center a string
def
center
(
s
,
width
):
n
=
len
(
s
)
if
n
>=
width
:
return
s
return
' '
*
((
width
-
n
)
/
2
)
+
s
+
' '
*
(
width
-
(
width
-
n
)
/
2
)
n
=
width
-
len
(
s
)
if
n
<=
0
:
return
s
half
=
n
/
2
if
n
%
2
and
width
%
2
:
# This ensures that center(center(s, i), j) = center(s, j)
half
=
half
+
1
return
' '
*
half
+
s
+
' '
*
(
n
-
half
)
# Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
# Decadent feature: the argument may be a string or a number
...
...
Lib/stringold.py
Dosyayı görüntüle @
fac38b7c
...
...
@@ -79,6 +79,20 @@ def splitfields(s, sep):
res
.
append
(
s
[
i
:])
return
res
# Join words with spaces between them
def
join
(
words
):
res
=
''
for
w
in
words
:
res
=
res
+
(
' '
+
w
)
return
res
[
1
:]
# Join fields with separator
def
joinfields
(
words
,
sep
):
res
=
''
for
w
in
words
:
res
=
res
+
(
sep
+
w
)
return
res
[
len
(
sep
):]
# Find substring
index_error
=
'substring not found in string.index'
def
index
(
s
,
sub
):
...
...
@@ -99,21 +113,25 @@ def atoi(str):
# Left-justify a string
def
ljust
(
s
,
width
):
n
=
len
(
s
)
if
n
>=
width
:
return
s
return
s
+
' '
*
(
width
-
n
)
n
=
width
-
len
(
s
)
if
n
<=
0
:
return
s
return
s
+
' '
*
n
# Right-justify a string
def
rjust
(
s
,
width
):
n
=
len
(
s
)
if
n
>=
width
:
return
s
return
' '
*
(
width
-
n
)
+
s
n
=
width
-
len
(
s
)
if
n
<=
0
:
return
s
return
' '
*
n
+
s
# Center a string
def
center
(
s
,
width
):
n
=
len
(
s
)
if
n
>=
width
:
return
s
return
' '
*
((
width
-
n
)
/
2
)
+
s
+
' '
*
(
width
-
(
width
-
n
)
/
2
)
n
=
width
-
len
(
s
)
if
n
<=
0
:
return
s
half
=
n
/
2
if
n
%
2
and
width
%
2
:
# This ensures that center(center(s, i), j) = center(s, j)
half
=
half
+
1
return
' '
*
half
+
s
+
' '
*
(
n
-
half
)
# Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
# Decadent feature: the argument may be a string or a number
...
...
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