An warware: menene %2A a cikin jerin gardama

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.

Shafi posts:

Leave a Comment