Sunday, October 8, 2017

basic string functions

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> sentence = "This is a string."
>>> letter =sentence[3]
>>> print (letter)
s
>>> print(len(sentence))
17
>>> words=sentence[5:10]
>>> print (words)
is a 
>>> wordList=sentence.split()
>>> print (wordList[3])
string.
>>> print (chr(960))
π
>>> print (ord("m"))
109

>>> sentence2 ="This is another sentence"
>>> for c in range(0,len(sentence2)):
 print(sentence2[c])

T
h
i
s
 
i
s
 
a
n
o
t
h
e
r
 
s
e
n
t
e
n
c
e
>>> mylist=["one","Two", "Three", "Four", "Five"]
>>> for str in mylist:
 print(str)

one
Two
Three
Four
Five

No comments:

Post a Comment