🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)
🔧 AI Nachrichten Stealing AI Reasoning Traces(08.09.2026 um 12:20 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)
🔧 AI Nachrichten Stealing AI Reasoning Traces(08.09.2026 um 12:20 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Day 4 :Everything You Need to Know About Functions in Python

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Definition and Defining Functions



A function represents some part of the code which can be executed only when required .In python, user defines the function by using def.




CODE
def sum(a,b):
print(a+b)






in this example we have performed a sum of two integers a,b. so.. whenever we require to sum two numbers, we can directly use the function sum(a,b).






Calling a Function



In Python, calling a function means executing the code defined inside a function block by using the function's name followed by parentheses. Here is an example for how calling is done in python:




CODE
def sum(a,b):
print(a+b)

sum(1,3)






here,





  • a and b are the parameters in the function definition.


  • 1, 3 are the arguments passed to the function.


  • sum is the name of the function



Generally, there are 4 types of Arguments:






1.Required Arguments



Required arguments are the parameters that a function must receive when it is called. If you do not provide the required arguments in a function call, Python will raise a TypeError because the function will not have the necessary information to execute.




CODE
sum(a,b):
print(a+b)
sum(1,3)

sum()






Output: 4

TypeError



Here:





  • a and b are required arguments because they do not have a default value.

  • So, when you call sum without an argument, Python raises an error.





2. Keyword Arguments



Keyword arguments allow you to pass arguments to a function by explicitly specifying the parameter names.




CODE
new_print(a,b):
print("{a} is a friend of {b}")
new_print(b="Alice" ,a="Bob")






Output: Bob is a friend of Alice

Here:




  • Since the Arguments are mentioned beforehand, in spite of wrong order, this code will produce this kind of result.





3. Default Arguments



Default arguments in Python allow you to define a function with default values for certain parameters. If a value for a parameter with a default is not provided during the function call, Python automatically assigns the default value. This makes functions more flexible and reduces the need to specify every parameter explicitly.




CODE
sum(a=0, b=0):
print(a+b)
sum()
sum(1,3)






Output: 0\n 4

In this example, even though, we have not assigned any variable to a, b since the a and b are assigned to a default value, it will give an output 0





4. Variable Length Arguments



Python provides a way to define functions that can accept a variable number of arguments. Variable-length arguments are handled using:




  1. *args (for non-keyword arguments)

  2. **kwargs (for keyword arguments)





1. *args:



*args allows a function to accept any number of positional arguments. Inside the function, these arguments are accessible as a tuple.




CODE
sum (*numbers):
sum=0
for i in numbers:
sum+=i
print(sum)
sum(1,2,3,4)






Output: 10






2. **Kwargs:



**kwargs allows a function to accept any number of keyword arguments (arguments passed as key=value pairs). These are stored in a dictionary.




CODE
sum(**numbers):
sum=0
for keys,values in numbers:
print("{keys}={numbers}")
sum+= values









💡Trick of the Day: 4 ways to swap the numbers



way 1:




CODE
P=5
Q=4
temp = P
P = Q
Q = temp






way 2:




CODE
P=5
Q=4
P,Q=Q,P






way 3:




CODE
P=5
Q=4
P = P ^ Q
Q = P ^ Q
P = P ^ Q






way 4:




CODE
P=5
Q=4
P = P + Q
Q = P - Q
P = P - Q


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
2 Quellen
News alert: Bright Security launches AI PT, AI-powered penetration testing that cuts weeks to hours
1 Quelle
Case study: ManageWP Blocks 11.9M+ Threats in 6 Months with Patchstack
1 Quelle
Unauthenticated PHP Object Injection to Remote Code Execution on GiveWP
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Day 4 :Everything You Need to Know About Functions in Python

Thematisch verwandte Begriffe: Everything, Need, Know, About · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...