.


:




:

































 

 

 

 





Python , , , , . , , , , , .

>>> an_integer = 1
>>> an_integer
1
>>> AN_INTEGER
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'AN_INTEGER' is not defined
>>> An_Integer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'An_Integer' is not defined
>>> an_inteGer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'an_inteGer' is not defined

:

( ):

"<stdin>", 1, <>

NameError: '<>'

.

Python .

Python , . , , , . humansize.py:

if __name__ == '__main__':
print(approximate_size(1000000000000, False))
print(approximate_size(1000000000000))

C, Python == = . C, Python , .

, if ? , , __name__ (). , . , __name__ , .

>>> import humansize
>>> humansize.__name__
'humansize'

, , __name__ __main__. Python if, , if. , .

c:\home\diveintopython3> c:\python31\python.exe humansize.py
1.0 TB
931.3 GiB

Python!

  • PEP 257: Docstring Conventions , .
  • Python Tutorial: Documentation Strings .
  • PEP 8: Style Guide for Python Code .
  • Python Reference Manual , Python , , .

  1. , , . . .
  2. string (). . .

 

, , .

Python . Python , . ? , Python .

Python . :

  1. , True () False ().
  2. , (1 2), (1.1 1.2), (1/2 2/3), .
  3. , , HTML-.
  4. , , JPEG.
  5. .
  6. .
  7. .
  8. -.

, . Python , , , , , , , . : , , . . ; .

, , . .

.

: . Python True ( . true ) False ( . false ), . . (, if), Python , . . , Python . , , , , . ( .)

, humansize.py:

if size < 0:
raise ValueError(' ')

size 0 , < . size < 0 . Python:

>>> size = 1
>>> size < 0
False
>>> size = 0
>>> size < 0
False
>>> size = -1
>>> size < 0
True

- , Python 2, . True 1, False 0.

>>> True + True
2
>>> True - False
1
>>> True * False
0
>>> True / False
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: int division or modulo by zero

:

( ):

"<stdin>", 1, <>

ZeroDivisionError:

--! ! , .

. , , . Python , . ; Python .

>>> type(1) ①
<class 'int'>
>>> isinstance(1, int) ②
True
>>> 1 + 1 ③
2
>>> 1 + 1.0 ④
2.0
>>> type(2.0)
<class 'float'>

type() . , 1 int ().
isinstance() .
int int.
int float float. Python int float, float.




:


: 2016-11-18; !; : 496 |


:

:

, .
==> ...

1728 - | 1608 -


© 2015-2024 lektsii.org - -

: 0.015 .