Yana kama da kuna neman jagorar rubutawa - musamman don ฦirฦirar labarin koyawa Python wanda yayi magana game da jerin muhawara "% 2A". Koyaya, a ฦasa akwai taฦaitaccen yadda ake ษaukar wannan.
Fahimtar Matsayin "%2A" a cikin Lissafin Hujjar Python
Python babban yaren shirye-shirye ne mai ฦarfi wanda ke ba masu haษaka damar rubuta hadaddun shirye-shirye a cikin ฦดan layukan lamba fiye da yadda zai yiwu tare da ฦananan harsuna. ฦayan fasalin da ke ba da gudummawa ga sauฦi da sassaucin ra'ayi na Python shine yadda yake tafiyar da muhawarar aiki, musamman amfani da "% 2A" a cikin jerin muhawarar.
"%2A" a cikin jerin gardama na Python shine nau'in alamar alamar (*), wanda ke taka muhimmiyar rawa wajen ma'anar aiki da kira. Yana ba da damar aiki kamar lissafin gardama na sabani da buษe abubuwan da ba za a iya cirewa ba a cikin kiran aiki.
def function(*args): for arg in args: print(arg) list = [1, 2, 3] function(*list)
Magani: Yin aiki tare da "% 2A" a cikin Lissafin Hujja
A cikin yaren Python, alamar alama (*) kayan aiki ne. Lokacin da aka sanya shi a lissafin gardama, Yana aiki azaman "kama-duk" don muhawarar kalmomin da ba na maษalli ba, tana adana su a cikin tuple. Yin amfani da "% 2A", wanda shine nau'in URL ษin da aka ษoye na "*", yana taimakawa hana al'amurra tare da software wanda ke fassara alamomi daban-daban.
def function(first, *remainder): print(first) print(remainder) function(1, 2, 3, 4, 5)
Tauraron (*) a cikin Python: Bayanin mataki-mataki
1. Ana bayyana aiki ta amfani da kalmar def, sannan sunan aikin.
2. A cikin lissafin gardama na aikin, ana ฦayyadadden hujja ta farko akai-akai.
3. Hujja ta biyu, duk da haka, tana gaba da alamar alama (*).
4. Wannan hujja ta biyu za ta tara duk wata hujja da aka bayar lokacin da aka kira aikin, daga na biyu zuwa gaba.
5. Waษannan ฦarin gardama an naษe su cikin tuple.
Ayyuka masu alaฦa da ษakunan karatu
Baya ga muhawarar aiki, alamar (*) kuma tana taka rawa a cikin wasu mahallin Python. A cikin buษaษษen buษaษษen, alal misali, ana iya amfani da shi don buษe abubuwan lissafin, tuples, da sauran abubuwan da za a iya jurewa.
numbers = [1, 2, 3, 4, 5] first, *remainder = numbers print(first) print(remainder)
A cikin wannan kwatancin, saura mai canzawa zai tattara duk wani abu da ba a sanya shi ga wasu masu canji ba. Don haka, alamar tambarin Python (*) ya zama kayan aiki na dabaru da yawa, yana mai da shi muhimmin al'amari na tsaftataccen ฦirar Python.