Inkinga ukuthi iPython ayinawo umsebenzi owakhelwe ngaphakathi wokususa izintambo eziningi ohlwini.
I have a list of strings: <code>list = ['a','b','c','d'] </code> and I want to remove multiple strings from the list, for example: <code>remove_list = ['a', 'c'] </code> A: You can use <code>set.difference()</code>: (If you don't mind the order of elements in your list) (If you want to keep the order of elements in your list, then use <code>filter()</code>) (If you want to keep only unique elements in your list, then use <code>set()</code>) (If you want to remove all duplicates from your list, then use <code>list(set())</code>) (If you want to remove all duplicates from your list and keep the order of elements as well, then use <code>[i for i in set(lst)]</code>)
Strings
Ku-Python, izintambo ziwukulandelana kwezinhlamvu. Izintambo zingasetshenziswa ukugcina umbhalo, izinombolo, nanoma yiluphi olunye uhlobo lwedatha.
Ukwakha intambo kuPython, usebenzisa umakhi wezintambo:
string = "Sawubona"
Ungakwazi futhi ukudala iyunithi yezinhlamvu ngokuhlanganisa izintambo ezimbili ndawonye:
string = "Sawubona" + "World"
Izinhlu
Ku-Python, izinhlu ziyisakhiwo sedatha esikuvumela ukuthi ugcine iqoqo lezinto. Uhlu lungase lungabi nalutho noma lungaqukatha noma yiluphi uhlobo lwento, kuhlanganise nolunye uhlu.
Ukwakha uhlu ku-Python, usebenzisa umsebenzi we-list(). Ukuze ufinyelele into yokuqala ohlwini, usebenzisa inkomba() umsebenzi. Ukuze ufinyelele into yokugcina ohlwini, usebenzisa i-len() umsebenzi.
Ukwengeza into ekugcineni kohlu, usebenzisa umsebenzi we-append(). Ukuze ususe into ekupheleni kohlu, usebenzisa umsebenzi we-pop().