Use d[i] to represent the i+1th character, which is similar to the index in the array, and the string can be regarded as an array
print(d[1],type(d[1]))
Use d[i:j] to intercept the string, for example, d[0:2] means to intercept the first character to the second character of the string d, and the character at index 2 cannot be intercepted
When using d[i:], it means that the interception is from the i+1th character to the last character
print(d[0:2],d[2:])
Use + to concatenate strings
print(d+e)
Use multiplexing strings, for example, d 3 means repeating the string d three times
print(d*3)
List list: equivalent to an array, the elements in the list are accessed through the index, the index value starts from 0, and the maximum value is the length of the list -1 (-1 can be used to represent the last element)
Elements of different data types can be stored in the list, which can be numbers, strings, Boolean values...
list1=[] means to define an empty list len(list1) means the length of the list
Tuples cannot be assigned twice, and this error will be reported when the following code is run:tuple1[0]="A" TypeError: 'tuple' object does not support item assignment
Therefore, a tuple is equivalent to an immutable list of lists
Set set: The set in Python is the same as the set concept in mathematics, and it is used to store unique elements, that is, the elements in the set are unique and different from each other.
Use {} to represent a collection, and use "," to separate each two elements
set1={
1,2,3,4,"A"}print(set1,type(set1))
When using the following code, the output result is: {1, 2, 3, 4} <class 'set'> Length: 4 Because the set collection cannot store repeated elements, when elements with the same value appear, they will be overwritten (that is, only save a value)
In a set, only immutable data types can be stored, including integers, floating-point types, strings, and tuples. Variable data types such as lists, dictionaries, and sets cannot be stored, otherwise the Python interpreter will throw a TypeError error.
set3={
1,"A",True,tuple1}print("set3:",set3)
The following code will prompt the following error:TypeError: unhashable type: 'list'
# set4={list1,set1}# print("set4:",set4)
Note that the set() function is used when creating an empty set collection, and a dictionary is created when using {}