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
90289281
Kaydet (Commit)
90289281
authored
Haz 01, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Forward port doc updates for builtin functions.
üst
affcf296
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
22 deletions
+32
-22
functions.rst
Doc/library/functions.rst
+32
-22
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
90289281
...
...
@@ -290,19 +290,18 @@ are always available. They are listed here in alphabetical order.
The resulting list is sorted alphabetically. For example:
>>> import struct
>>> dir() #
doctest: +SKIP
>>> dir() #
show the names in the module namespace
['__builtins__', '__doc__', '__name__', 'struct']
>>> dir(struct) #
doctest: +NORMALIZE_WHITESPACE
>>> dir(struct) #
show the names in the struct module
['Struct', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
'unpack', 'unpack_from']
>>> class Foo:
... def __dir__(self):
... return ["kan", "ga", "roo"]
...
>>> f = Foo()
>>> dir(f)
['ga', 'kan', 'roo']
>>> class Shape(object):
def __dir__(self):
return ['area', 'perimeter', 'location']
>>> s = Shape()
>>> dir(s)
['area', 'perimeter', 'location']
.. note::
...
...
@@ -333,15 +332,21 @@ are always available. They are listed here in alphabetical order.
:meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
tuple containing a count (from *start* which defaults to 0) and the
corresponding value obtained from iterating over *iterable*.
:func:`enumerate` is useful for obtaining an indexed series: ``(0, seq[0])``,
``(1, seq[1])``, ``(2, seq[2])``, .... For example:
>>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter']):
... print(i, season)
0 Spring
1 Summer
2 Fall
3 Winter
>>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1):
print(i, season)
1 Spring
2 Summer
3 Fall
4 Winter
Equivalent to::
def enumerate(sequence, start=0):
n = start
for elem in sequence:
yield n, elem
n += 1
.. function:: eval(expression, globals=None, locals=None)
...
...
@@ -652,10 +657,10 @@ are always available. They are listed here in alphabetical order.
One useful application of the second form of :func:`iter` is to read lines of
a file until a certain line is reached. The following example reads a file
until
``"STOP"`` is reached:
::
until
the :meth:`readline` method returns an empty string
::
with open(
"mydata.txt"
) as fp:
for line in iter(fp.readline,
"STOP"
):
with open(
'mydata.txt'
) as fp:
for line in iter(fp.readline,
''
):
process_line(line)
...
...
@@ -1169,8 +1174,9 @@ are always available. They are listed here in alphabetical order.
It can be called either on the class (such as ``C.f()``) or on an instance (such
as ``C().f()``). The instance is ignored except for its class.
Static methods in Python are similar to those found in Java or C++. For a more
advanced concept, see :func:`classmethod` in this section.
Static methods in Python are similar to those found in Java or C++. Also see
:func:`classmethod` for a variant that is useful for creating alternate class
constructors.
For more information on static methods, consult the documentation on the
standard type hierarchy in :ref:`types`.
...
...
@@ -1270,6 +1276,10 @@ are always available. They are listed here in alphabetical order.
references. The zero argument form automatically searches the stack frame
for the class (``__class__``) and the first argument.
For practical suggestions on how to design cooperative classes using
:func:`super`, see `guide to using super()
<http://rhettinger.wordpress.com/2011/05/26/super-considered-super/>`_.
.. function:: tuple([iterable])
...
...
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