Text in Python | Text Data Type | Python Data Type | Python String | String in Python |
Python can manipulate text (represented by type str, so-called “strings”) as well as numbers. This includes characters “!”, words “rabbit”, names “Paris”, sentences “Got your back.”, etc. “Yay! :)”. They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.
print("Hello ! :) Welcome Here")
print('Hello ! :) Welcome Here')
print('2023')
print(2023)
print(2020)
print('T20')
To quote a quote, we need to “escape” it, by preceding it with \. Alternatively, we can use the other type of quotation marks:
print('doesn\'t')
print("doesn\'t")
print('"Yes," they said.')
print("\"Yes,\" they said.")
print('"Isn\'t," they said.')
In the Python shell, the string definition and output string can look different. The print() function produces a more readable output, by omitting the enclosing quotes and by printing escaped and special characters:
s = 'First line.\nSecond line.' # \n means newline
s # without print(), special characters are included in the string
'First line.\nSecond line.'
print(s) # with print(), special characters are interpreted, so \n produces new line
First line.
Second line.
If you don’t want characters prefaced by \ to be interpreted as special characters, you can use raw strings by adding an r before the first quote:
print('Devvrat\nKnowledgevilla')
name = r'C:\some\name' #raw string python
print(name)
There is one subtle aspect to raw strings: a raw string may not end in an odd number of \ characters; see the FAQ entry for more information and workarounds.
String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line. The following example:
print("""
Python can manipulate text (represented by type str, so-called “strings”) as well as numbers.
This includes characters “!”, words “rabbit”, names “Paris”, sentences “Got your back.”, etc. “Yay! :)”.
They can be enclosed in single quotes ('...') or double quotes ("...") with the same result.
""")
Strings can be concatenated (glued together) with the + operator, and repeated with *:
print(3 * "dev""vrat")
print(3 * "dev"+"vrat")
Two or more string literals (i.e. the ones enclosed between quotes) next to each other are automatically concatenated.
print("dev""vrat")
If you want to concatenate variables or a variable and a literal, use +:
name = "dev"
print(name +'vrat')
This feature is particularly useful when you want to break long strings:
text = ('Put several strings within parentheses '
'to have them joined together.')
print(text)
This only works with two literals though, not with variables or expressions:
prefix = 'Py'
prefix 'thon' # can't concatenate a variable and a string literal
File "stdin", line 1
print(prefix 'thon')
^^^^^^
SyntaxError: invalid syntax
('un' * 3) 'ium'
File "stdin", line 1
('un' * 3) 'ium'
^^^^^
SyntaxError: invalid syntax
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Text in Python | Text Data Type | Python Data Type | Python String | String in Python |», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.