dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print dict['one'] # Prints value for 'one' key
print dict[2] # Prints value for 2 key
print tinydict # Prints complete dictionary
print tinydict.keys() # Prints all the keys
print tinydict.values() # Prints all the values
Я попытался добавить круглые скобки к содержимому кода Python и должен заменить «#» на «) #», поскольку знак хеша подразумевает комментарии в редакторе.'print' также заменяется на 'print ('
and addended ')' для кода Python
Результат должен был выглядеть следующим образом:
print (tinydict.values() )# Prints all the values)
Я поместил этот код вочистите таблицу Excel и запустите код vba ниже
Sub macro1()
Set Rng = Range([a1], [p40])
For Each c In Rng
If IsEmpty(c.Value) = False Then
If c Like "*print*" Then
c.Replace _
What:="print", Replacement:="print (", _
SearchOrder:=xlByRows, lookat:=xlPart
c.Value = c.Value & ")" 'appending ) at the end'
End If
If c Like "*#*" Then
c.Replace _
What:="#", Replacement:=")#", _
SearchOrder:=xlByRows, lookat:=xlPart
End If
End If
Next c
End Sub
, однако, он работает только для второй строки кода
print ( dict[2] )# print (s value for 2 key)
Остальная часть строки, которая содержит '#', не затронула.
Мне было интересно, что вызвало это.
Tnx