0
About Import and If
Just a question based out of pure curiosity, right now I am at the part of the course where I am learning about If (If x > 5 then a, for example) but how do I use the value from import for this function, what would be a line I could use?
3 odpowiedzi
+ 12
#you don't ... ?
#well I mean, you can use functions from the module you imported. for example:
import random
answer = random.choice(["Red","Blue"])
print(answer)
#here you import random, and use it's choice function to choose a random color, and assign that string to a variable. I hope this is the sort of thing you mean, since I don't think you can do:
# a = import random
#however I do think it's possible to do:
importstring="import random"
exec(importstring)
#which interprets the string and runs it as code. however generally you're just going to want to do imports at the start of your code and not fiddle with assigning variables imports. sorry if I misunderstood, I have a headache and am tired .
+ 3
what do you mean the value from import?
x=6
if x>5:
print("Yup")
else:
print("Nope")
+ 3
def add(x,b):
c=x+b
return c
add(5,4)