Sei sulla pagina 1di 3

String

November 7, 2017

In [1]: 'hello'

Out[1]: 'hello'

In [3]: "This is a string"

Out[3]: 'This is a string'

In [4]: 'I'm a string'

File "<ipython-input-4-2012e21e64cc>", line 1


'I'm a string'
ˆ
SyntaxError: invalid syntax

In [5]: "I'm a string"

Out[5]: "I'm a string"

In [6]: 'I\'m a string'

Out[6]: "I'm a string"

In [7]: 'Hello World'

Out[7]: 'Hello World'

In [11]: print ('Hello World 1')


print ('Hello World 2')

Hello World 1
Hello World 2

In [12]: print('Here is a new line \n and there is the second line')

1
Here is a new line
and there is the second line

In [13]: print('Here is a new line \t and there is the second line')

Here is a new line and there is the second line

In [14]: len('Hello World')

Out[14]: 11

In [17]: a = 'Hello'

In [18]: a[0]

Out[18]: 'H'

In [19]: a[:2]

Out[19]: 'He'

In [20]: a[:]

Out[20]: 'Hello'

In [22]: a[::2]

Out[22]: 'Hlo'

In [23]: a[0] = 'h'

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

<ipython-input-23-e7d5244db00b> in <module>()
----> 1 a[0] = 'h'

TypeError: 'str' object does not support item assignment

In [25]: a[::-1]

Out[25]: 'olleH'

In [26]: a = 'h'+a[1:]

2
In [27]: a

Out[27]: 'hello'

In [31]: letter = 'Notebook'

In [32]: letter

Out[32]: 'Notebook'

In [33]: letter*10

Out[33]: 'NotebookNotebookNotebookNotebookNotebookNotebookNotebookNotebookNotebookNotebook'

In [34]: s = 'Hello'

In [35]: s.upper()

Out[35]: 'HELLO'

Potrebbero piacerti anche