In [8]:
>>> 'Hello world 2!' #single quoto


Out[8]:
'Hello world 2!'

In [9]:
>>> 'father\'s friend' # \' is used to escape single quoto


Out[9]:
"father's friend"

In [10]:
>>> "mother's friend" #"" or use double quoto


Out[10]:
"mother's friend"

In [12]:
>>> '"Yes", he said'


Out[12]:
'"Yes", he said'

In [14]:
>>> "\"yes\" he said."


Out[14]:
'"yes" he said.'

In [15]:
>>> '"isn\'t it" she said '


Out[15]:
'"isn\'t it" she said '

In [16]:
>>> print ('"isn\'t it" she said') #区别在于把不要的引号给忽略了


"isn't it" she said

In [19]:
>>> s = 'first line .\nsecond line' #\n means newline

In [20]:
>>> s #without print \n is included in the output


Out[20]:
'first line .\nsecond line'

In [21]:
>>> print (s) # with print \n produces a new line.


first line .
second line

In [22]:
>>> print ('C:\one\name')


C:\one
ame

In [26]:
>>> print (r'C:\one\name') # r means raw string


C:\one\name

In [33]:
>>> print("""\
weahter: whether condition
     temperature           display temperature
     sun                   display whether if it is a sunny day
""")  #"""\"""  \可以阻止打印的第一行空白


weahter: whether condition
     temperature           display temperature
     sun                   display whether if it is a sunny day


In [35]:
>>> 3*"uni" + "form" #string can be connected by +


Out[35]:
'uniuniuniform'

In [36]:
>>> "Hello" "world" "three" #two or more string are connected to each other


Out[36]:
'Helloworldthree'

In [37]:
>>> s = "hello"
s "world" #variable and string could not connected to each other


  File "<ipython-input-37-b2c9ebc01c60>", line 2
    s "world"
            ^
SyntaxError: invalid syntax

In [38]:
>>> s = "Hello" 
s + "world" # However a variable and string could be connected by using "+"


Out[38]:
'Helloworld'

In [41]:
>>> word  = "Python"
>>> word [0]    #Character in position 0


Out[41]:
'P'

In [43]:
>>> word [-5]  # counting from right by using "-" and negative starts from "-1"


Out[43]:
'y'

In [44]:
>>> word [0:4] # character 0 to character 4, 0 included and 4 excluded


Out[44]:
'Pyth'

In [45]:
>>> word [:2] + word [2:] # n[:i]+n[i:] = n


Out[45]:
'Python'

In [46]:
>>> word [34:] #超出部分也没事


Out[46]:
''

In [47]:
>>> s = "todayswtherisreallygood"
len(s) #len() could display string length


Out[47]:
23

In [ ]: