上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Sequences ● Sequences represent finite ordered sets Indexed by non-negative numbers -a[0],a[1],a[2],a[3],a[4],a[5],a[6],…a[n-1] Sequences support slicing: a[i:j]selects all items with index x where i<=x j. Some sequences also support "extended slicing”: a[i:j:k]selects all items of a with index x where x=i+n*k,n>=0 and i<=x<j. >>>b=a[1:7:2]: 16
Sequences • Sequences represent finite ordered sets – Indexed by non-negative numbers – a[0],a[1],a[2],a[3],a[4],a[5],a[6], ... a[n-1] • Sequences support slicing: – a[i:j] selects all items with index x where i <= x < j. • Some sequences also support “extended slicing”: – a[i:j:k] selects all items of a with index x – where x = i + n*k, n >= 0 and i <= x < j. >>>b=a[1:7:2]: 16
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY The String Data Type >>str1="HelloT >>str2='spam' >>print(str1,str2) Hello spam >>type(str1) <class 'str'> >>type(str2) <class 'str'> 17
17 The String Data Type >>> str1="Hello" >>> str2='spam' >>> print(str1, str2) Hello spam >>> type(str1) <class 'str'> >>> type(str2) <class 'str'>
上游充通大学 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY The String Data Type Getting a string as input >>firstName input("Please enter your name:" Please enter your name:John >>print "Hello",firstName Hello John Difference of input and raw_input!(recall) 18
18 The String Data Type • Getting a string as input >>> firstName = input("Please enter your name: ") Please enter your name: John >>> print "Hello", firstName Hello John • Difference of input and raw_input!(recall)