In [8]:
>>> 'Hello world 2!' #single quoto
Out[8]:
In [9]:
>>> 'father\'s friend' # \' is used to escape single quoto
Out[9]:
In [10]:
>>> "mother's friend" #"" or use double quoto
Out[10]:
In [12]:
>>> '"Yes", he said'
Out[12]:
In [14]:
>>> "\"yes\" he said."
Out[14]:
In [15]:
>>> '"isn\'t it" she said '
Out[15]:
In [16]:
>>> print ('"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]:
In [21]:
>>> print (s) # with print \n produces a new line.
In [22]:
>>> print ('C:\one\name')
In [26]:
>>> print (r'C:\one\name') # r means raw string
In [33]:
>>> print("""\
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]:
In [36]:
>>> "Hello" "world" "three" #two or more string are connected to each other
Out[36]:
In [37]:
>>> s = "hello"
s "world" #variable and string could not connected to each other
In [38]:
>>> s = "Hello"
s + "world" # However a variable and string could be connected by using "+"
Out[38]:
In [41]:
>>> word = "Python"
>>> word [0] #Character in position 0
Out[41]:
In [43]:
>>> word [-5] # counting from right by using "-" and negative starts from "-1"
Out[43]:
In [44]:
>>> word [0:4] # character 0 to character 4, 0 included and 4 excluded
Out[44]:
In [45]:
>>> word [:2] + word [2:] # n[:i]+n[i:] = n
Out[45]:
In [46]:
>>> word [34:] #超出部分也没事
Out[46]:
In [47]:
>>> s = "todayswtherisreallygood"
len(s) #len() could display string length
Out[47]:
In [ ]: