Skip to content
← Back to Community
Variables on python
Profile icon
AlfiePython

How do I create a variable with python code so I can do things like

A = 5
print ("A")

which the result is 5

Answered by MocaCDeveloper [earned 5 cycles]
View Answer
Voters
Profile icon
AlfiePython
Comments
hotnewtop
Profile icon
MocaCDeveloper

Simple!

variable_name = "Value" print(variable_name)

In Python, you can assign any value to your variable.
What's better? Even have you have, lets say a string, assigned to your variable, you can still assign a integer to it and it will change the value compiler

The powers of a dynamic language!

Profile icon
elburg

@MocaCDeveloper
also, these commands are helpful:

image

However, if a variable is created inside a function, it will only be used inside that function and can never be called anywhere else besides the function itself. if the variable is created on the outside, it can be used with the entire program, but only in the file that it was created in.

Profile icon
AlfiePython

Thank you