23
loading...
This website collects cookies to deliver better user experience
type(32)
# Output is <class 'int'>
numbers = [4,6,1,0,56,78]
print(max(numbers)) # returns 78
print(min(numbers)) # returns 0
>>> int('32') #returns 32
>>> int('Hello')
""" Returns value error. ValueError:
invalid literal for int() with base 10: 'Hello' """
>>>int(3.455966696) # returns 3
>>>float(32) #returns 32.0
>>> float('3.14159') #returns 3.14159
>>> str(40) # returns '40'
>>> str(23.9) # returns '23.9'
import random
for x in range(10):
x = random.random()
print(x)
# returns 10 random numbers.
>>> random.randint(5,9) # returns any number from 5 to 9
t = [3,6,4]
>>> random.choice(t) #returns any value
import math
>>> degrees = 45
>>> radians = degrees/360.0 * 2 * math.pi
>>>math.sin(radians)
#defining a function in python
def function_name(parameters): #may or may not have
#parameters
# function statements here
def movie_titles():
print("Coming 2 America")
print("Out of Death")
print("War room")
movie_title() # function call
#Output is the movie titles above
list = [2,5,6,3]
def count_list(list):
count = 0
for number in list:
count = count + 1
return count
print(f"The number of items in the list is {count_list(list)})
def add(a,b):
added = a + b
return added
x = add(3,5) # returns 8. 5 and 3 are the arguments of the function.