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
15b5e55b
Kaydet (Commit)
15b5e55b
authored
Ock 10, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Neaten-up the named tuple docs
üst
d08a8ebf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
collections.rst
Doc/library/collections.rst
+7
-7
collections.py
Lib/collections.py
+1
-1
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
15b5e55b
...
@@ -364,8 +364,8 @@ they add the ability to access fields by name instead of position index.
...
@@ -364,8 +364,8 @@ they add the ability to access fields by name instead of position index.
method which lists the tuple contents in a ``name=value`` format.
method which lists the tuple contents in a ``name=value`` format.
The *fieldnames* are a single string with each fieldname separated by whitespace
The *fieldnames* are a single string with each fieldname separated by whitespace
and/or commas
(for example 'x y' or 'x, y')
. Alternatively, *fieldnames*
and/or commas
, for example ``'x y'`` or ``'x, y'``
. Alternatively, *fieldnames*
can be a sequence of strings
(such as ['x', 'y'])
.
can be a sequence of strings
such as ``['x', 'y']``
.
Any valid Python identifier may be used for a fieldname except for names
Any valid Python identifier may be used for a fieldname except for names
starting with an underscore. Valid identifiers consist of letters, digits,
starting with an underscore. Valid identifiers consist of letters, digits,
...
@@ -373,7 +373,7 @@ they add the ability to access fields by name instead of position index.
...
@@ -373,7 +373,7 @@ they add the ability to access fields by name instead of position index.
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
or *raise*.
or *raise*.
If *verbose* is true,
will print the class definition
.
If *verbose* is true,
the class definition is printed just before being built
.
Named tuple instances do not have per-instance dictionaries, so they are
Named tuple instances do not have per-instance dictionaries, so they are
lightweight and require no more memory than regular tuples.
lightweight and require no more memory than regular tuples.
...
@@ -518,16 +518,16 @@ a fixed-width print format::
...
@@ -518,16 +518,16 @@ a fixed-width print format::
... def hypot(self):
... def hypot(self):
... return (self.x ** 2 + self.y ** 2) ** 0.5
... return (self.x ** 2 + self.y ** 2) ** 0.5
... def __str__(self):
... def __str__(self):
... return 'Point: x=%6.3f
y=%6.3f
hypot=%6.3f' % (self.x, self.y, self.hypot)
... return 'Point: x=%6.3f
y=%6.3f
hypot=%6.3f' % (self.x, self.y, self.hypot)
>>> for p in Point(3, 4), Point(14, 5/7.):
>>> for p in Point(3, 4), Point(14, 5/7.):
... print p
... print p
Point: x= 3.000
y= 4.000
hypot= 5.000
Point: x= 3.000
y= 4.000
hypot= 5.000
Point: x=14.000
y= 0.714
hypot=14.018
Point: x=14.000
y= 0.714
hypot=14.018
Another use for subclassing is to replace performance critcal methods with
Another use for subclassing is to replace performance critcal methods with
faster versions that bypass error-checking
and that localize variable access
::
faster versions that bypass error-checking::
class Point(namedtuple('Point', 'x y')):
class Point(namedtuple('Point', 'x y')):
__slots__ = ()
__slots__ = ()
...
...
Lib/collections.py
Dosyayı görüntüle @
15b5e55b
...
@@ -123,7 +123,7 @@ if __name__ == '__main__':
...
@@ -123,7 +123,7 @@ if __name__ == '__main__':
def
hypot
(
self
):
def
hypot
(
self
):
return
(
self
.
x
**
2
+
self
.
y
**
2
)
**
0.5
return
(
self
.
x
**
2
+
self
.
y
**
2
)
**
0.5
def
__str__
(
self
):
def
__str__
(
self
):
return
'Point: x=
%6.3
f
y=
%6.3
f
hypot=
%6.3
f'
%
(
self
.
x
,
self
.
y
,
self
.
hypot
)
return
'Point: x=
%6.3
f
y=
%6.3
f
hypot=
%6.3
f'
%
(
self
.
x
,
self
.
y
,
self
.
hypot
)
for
p
in
Point
(
3
,
4
),
Point
(
14
,
5
/
7.
):
for
p
in
Point
(
3
,
4
),
Point
(
14
,
5
/
7.
):
print
p
print
p
...
...
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