Created
December 11, 2011 19:39
-
-
Save dketov/1462316 to your computer and use it in GitHub Desktop.
Строка, часть 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Вывод строки | |
""" | |
i = 256 * 256 | |
print 'The value of i is', i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Подстановка | |
""" | |
S = 'spammy' | |
S = S.replace('mm', 'xx') | |
print S | |
print 'aa$bb$cc$dd'.replace('$', 'SPAM') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Разбиение | |
""" | |
string1 = "A, B, C, D, E, F" | |
print "String is:", string1 | |
print "Split string by spaces:", string1.split() | |
print "Split string by commas:", string1.split( "," ) | |
print "Split string by commas, max 2:", string1.split( ",", 2 ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Объединение | |
""" | |
print 'SPAM'.join(['eggs', 'sausage', 'ham', 'toast']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Форматирование | |
""" | |
print "%2s %5s %12s" % ('x', 'x**2', 'x**x') | |
print "=" * 21 | |
for x in range(1,6): | |
print "%2d %5d %12d" % (x, x**2, x**x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Объединение с форматированием | |
""" | |
list1 = [ "A", "B", "C", "D", "E", "F" ] | |
string2 = "___" | |
print "List is:", list1 | |
print 'Joining with "%s": %s' \ | |
% ( string2, string2.join ( list1 ) ) | |
print 'Joining with "-.-":', "-.-".join( list1 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment