“Python -Funktionen” Code-Antworten

So codieren Sie eine Funktion in Python

def hi():
  print("hi!")
  
Curious Cowfish

#Funktion in Python

#Function in python

def identity(age):
    print("You are "+str(age)+" Years old")
identity(input("Type your age: "))

def id(name):
    print("Hello "+name+"."+"You are our valued customer")
    print("Have a nice Day "+name)
id(input("Type your name: "))

# if you want to use the input method to get the user info more
# than one time then you should make two function.
# In one function you can't get the multiple results.if anyone can find
# please add to greeper ans.
YEASIN ARAFAT

Definition der Funktion in Python

# defining a function  
def my_func():  
    print("Greetings User! Welcome to Softhunt.net")  
  
# calling the function  
my_func()
Outrageous Ostrich

Funktion Python

#math function in python:
def math(x,y):
    z = x * y
    return z
A = math(7,8)
print(A)
YEASIN ARAFAT

Python -Funktionen

def myfunction():{print(5), print(6)}
Bob7012

Python -Funktionen

'''
Functions are very useful in python because you can use them instead
of repeating code in your program which makes your code messy.
'''

# This is how you create a function
def functionName():
  print('Hello World!')
  
functionName() # prints out 'Hello World!'
functionName() # prints out 'Hello World!' again

# Functions can have attributes which you insert into the function
def add(a, b):
  print(a + b)
  
add(2, 4) # prints out '6'
add(11, 35) # prints out '46'

# Finally, functions can return values which you can save as variables
def addFive(value):
  return value + 5

myVar = addFive(3) # myVar becomes equal to 8 (3 + 5)
print(myVar) # prints out myVar

'''
Keep in mind that scope comes into play in your functions. If you
create a variable in a function, it won't be saved outside the
function.
'''
def createVar():
	myVar = 5
    
createVar()
print(myVar) # returns error (unless you defined myVar outside function)
Ninja Penguin

Ähnliche Antworten wie “Python -Funktionen”

Fragen ähnlich wie “Python -Funktionen”

Weitere verwandte Antworten zu “Python -Funktionen” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen