-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathpython_strings.py
More file actions
executable file
·44 lines (32 loc) · 1.31 KB
/
python_strings.py
File metadata and controls
executable file
·44 lines (32 loc) · 1.31 KB
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
#!/usr/bin/python
#Note: Python strings are immutable
#Strings can be enclosed in single quotes
print 'Hello World in single quotes'
#Strings can also be enclosed in double quotes
print "Hello World in double quotes"
#Strings can also be enclosed in triple quotes
print """ This is a multiline string
Such strings are also possible in Groovy.
These strings can contain ' as well as " quotes """
#Strings can be continued on the next line
print "This string is continued on the\
next line (in the source) but a newline is not added"
#Raw strings
print r"The newline character is represented with \n"
#The following is a unicode string, but here it is a literal.
#How do we specify that a string read from a file should be held
#as a unicode string. Also the +uXXXX notation does not work in
#Python
print u"This is a unicode string u0600"
#See how the strings are concatenated
print 'hello ' 'world'
#Notice how the print statement accepts , separated values
print '2 + 3 = ', (2+3)
#Getting the length of a string
greeting = "Hello my dear friend how are you?"
print "the length of string '" ,greeting, "' is ", len(greeting)
#Let's check if the string contains the word 'Hello'
if('Hello' in greeting):
print 'This greeting seems to be in English'
if(greeting.find('Hello') != -1):
print 'This greeting seems to be in English'