Catalog
List is a non numeric data type .
Iterate through
Tuples (Tuple)
How to define a tuple that contains only one element ?
Dictionaries
character string
python Built in functions
list_test = [" A waste of time ", " The secret of success ", " Don't look for someone "]
print(list_test)
index function
effect : Find the subscript of a data .
list_test = [" A waste of time ", " The secret of success ", " Don't look for someone "]
print(list_test.index(" A waste of time "))
del keyword
effect : Delete a variable from memory .
ff = "ff"
del ff
print(ff)
list_test = [" Don't waste time ", " The secret of success ", " Don't look for someone "]
for my in list_test:
print(" remember %s" % my)
# Iterate through
Tuples are similar to lists , The difference is that the elements of a tuple cannot be modified .
Tuples : A sequence of elements .
Used to store a string of information , Between data “,” Separate .
Tuple use () To define .
When defining a tuple that contains only one element like this ,python The interpreter will automatically ignore the parentheses . You need to use commas to separate .
single_tuple = (5,)
print(type(single_tuple))
Tuple correlation function :
index() and count().
Tuple traversal can also be done iteratively .
If you want to modify the tuple, you can use list Function to list , It can be modified .
If you don't want the list to be modified , You can go through tuple Function to tuple .
Dictionary use {} Definition . It uses key value pairs to store data , Key value pairs are separated by commas .
key Key It's the index .
value value Is the data .
Keys and values are preceded by : Separate .
Keys are unique , Cannot have more than one key with the same name .
Values can be of any data type , But keys can only use strings , A number or tuple .
The difference between a dictionary and a list : A list is an ordered collection of objects , A dictionary is an unordered collection of objects .
It is usually used to store information about an object .
xiaoming_inf = {"name": " kitten ", "age": 17}
print(xiaoming_inf["name"])
python You can use either double quotation marks or single quotation marks to define .
Many methods are defined in the string , The subscript is found , have access to find function , This function is related to index Difference of function :find() If a non-existent value is found, it will be returned directly -1 No errors are reported ,index Will report an error directly .
The methods in the string are mainly about judging white space characters , Judge whether it is a number , Find and replace , Case write , Alignment mode .