Created
December 11, 2011 19:35
-
-
Save dketov/1462293 to your computer and use it in GitHub Desktop.
Строка, часть 1
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 eggs' | |
print 'doesn\'t' | |
print "doesn't" | |
print '"Yes," he said.' | |
print "\"Yes,\" he said." | |
print '"Isn\'t," she said.' |
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 -*- | |
""" | |
Сцепление и повторение строк | |
""" | |
word = 'Help' + 'A' | |
print word | |
print '<' + word*5 + '>' |
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 -*- | |
""" | |
Многострочная строчка | |
""" | |
# Continuation lines can be used, with a backslash as the last character on the | |
# line indicating that the next line is a logical continuation of the line: | |
hello = "This is a rather long string containing\n\ | |
several lines of text just as you would do in C.\n\ | |
Note that whitespace at the beginning of the line is\ | |
significant." | |
print hello |
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 -*- | |
""" | |
Многострочная строчка 2 | |
""" | |
mantra = """Always look | |
... on the bright | |
... side of life.""" | |
print mantra |
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 int("42"), str(42) # convert from/to string | |
print int("42") + 1 # force addition | |
print int("42"), str(42) # convert from/to string | |
print "spam" + str(42) # force concatenation |
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 = 'spam' | |
S.isalpha() # Content tests: isalpha, isdigit, etc. |
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 -*- | |
""" | |
Изменение регистра | |
""" | |
quote = "Python is easy to use." | |
print "Original quote:" | |
print quote | |
print "\nIn uppercase:" | |
print quote.upper() | |
print "\nOriginal quote is still:" | |
print quote |
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 = 'supercalifragilisticexpialidocious' | |
print len(s) |
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 = 'a\0b\0c' | |
print s | |
print len(s) |
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 -*- | |
""" | |
Обратный слэш в строке | |
""" | |
x = "C:\py\code" # keeps \ literally | |
print x | |
print len(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment