python built in functions code example
Example 1: python functions
def myFunction(say):
print(say)
myFunction("Hello")
age = input("How old are you?")
myFunction("You are {} years old!".format(age))
Hello
How old are you?
>>11
You are 11 years old!
Example 2: modules in python
import random
r = random.randint(1,10)
from random import randint
r = randint(1,10)
from random import *
r = randint(1,10)
Example 3: functions in python
""" All the functions are followed by the 'def' keyword in python"""
def Greet(User):
print("Hello" + User + "!")
Greet("Shivram")
Example 4: python3 any
l = [1, 3, 4, 0]
print(any(l))
l = [0, False]
print(any(l))
l = [0, False, 5]
print(any(l))
l = []
print(any(l))
Example 5: python functions list
def all(iterable):
for element in iterable:
if not element:
return False
return True
Example 6: len python 3
len(list)