Строка, часть 1
# -*- encoding: utf-8 -*-
"""
Обратный слэш в строке
"""
x = "C:\py\code" # keeps \ literally
print x
print len(x)
# -*- encoding: utf-8 -*-
"""
Строка со специальными символами
"""
s = 'a\0b\0c'
print s
print len(s)
# -*- encoding: utf-8 -*-
"""
Длина строки
"""
s = 'supercalifragilisticexpialidocious'
print len(s)
# -*- 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
# -*- encoding: utf-8 -*-
"""
Содержимое строки
"""
S = 'spam'
S.isalpha() # Content tests: isalpha, isdigit, etc.
# -*- 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
# -*- encoding: utf-8 -*-
"""
Многострочная строчка 2
"""
mantra = """Always look
... on the bright
... side of life."""
print mantra
# -*- 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
# -*- encoding: utf-8 -*-
"""
Сцепление и повторение строк
"""
word = 'Help' + 'A'
print word
print '<' + word*5 + '>'
# -*- 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.'