-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStringsDemo.py
51 lines (51 loc) · 941 Bytes
/
StringsDemo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> a = "hello this is python and python is used for machine learning"
>>> a[0]
'h'
>>> a[-1]
'g'
>>> a[0:5]
'hello'
>>> a[10:20]
' is python'
>>> a[0:20:2]
'hloti spto'
>>> a[0:20:1]
'hello this is python'
>>> a[0:20:2]
'hloti spto'
>>> a[-1:-10]
''
>>> a[20:10]
''
>>> a[20:10:-1]
' nohtyp si'
>>> a[10]
' '
>>> a[20]
' '
>>> a[0:10]
'hello this'
>>> a[10:0:-1]
' siht olle'
>>> a[-1:-10]
''
>>> a[-1:-10:-1]
'gninrael '
>>> a[-1]
'g'
>>> a[:]
'hello this is python and python is used for machine learning'
>>> a[::-1]
'gninrael enihcam rof desu si nohtyp dna nohtyp si siht olleh'
>>> x = 'hello'
>>> x[::-1]
'olleh'
>>> a[-1::]
'g'
>>> a[-1::-1]
'gninrael enihcam rof desu si nohtyp dna nohtyp si siht olleh'
>>> a[-1:-10]
''
>>>