Новости
Библиотека
Е-книги
Авторское
Форум
Каталог ссылок
Каталог ПО
О сайте
Карта сайта
Наши партнеры
Книги по Linux
(с отзывами читателей)
Библиотека сайта rus-linux.net
Р.Сузи. Спецкурс "Язык Python и его приложения" Практическое занятие 1
Практическое занятие 1.
$ python Python 1.5.2 (#1, Apr 3 2002, 18:16:26) [GCC 2.96 20000731 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> 2+2 4 >>> 2**1000L 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376L >>> import math >>> math.sin(2.3) 0.745705212177 >>> from math import * >>> sin(2.3) 0.745705212177 >>> print "apple" apple >>> "apple" 'apple' >>> print str("apple") apple >>> print repr("apple") 'apple' >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[:4] [0, 1, 2, 3] >>> l[-2:] [8, 9] >>> l[0:len(l)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[1:1]=[8,8,8] >>> l [0, 8, 8, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> for i in range(10): ... print hex(i) ... 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 >>> for i in range(10): ... print hex(i), ... 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 >>> import string >>> string.replace("people", "peo", "ap") 'apple' >>> string.split("1,2,3", ",") ['1', '2', '3'] >>> map(int, string.split("1,2,3", ",")) [1, 2, 3] >>> "a" * 10 'aaaaaaaaaa' >>> [1,2,3]*10 [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] >>> [1,2] + [3,4] [1, 2, 3, 4] >>> import time >>> time.time() 1035719478.04 >>> time.localtime(_) (2002, 10, 27, 14, 51, 18, 6, 300, 0) >>> time.localtime(time.time()) (2002, 10, 27, 14, 51, 38, 6, 300, 0) >>> time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(time.time())) '27.10.2002 14:52:22' >>>
-
$ mc
-
#!/usr/bin/python print """ Hello, World! """
primer.py
chmod +x primer.py ./primer.py