Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python How are you able to create variables?

Hello, Welcome to Code Forum!

Just for future reference, always post the code rather than a picture (although this doesn't have a lot of code). This helps us copy and paste the code into our editors to test and perhaps troubleshoot it much quicker.

Just to clarify, you want to swap a and b? You can probably try creating another variable call temp, then have A go-to temp. Then B goes to A, followed by A from temp to B.

Using temp variable swap:
[CODE title=Example]a = [1,2,3]
b = [3,2,1]
temp = [0]

temp = b;
b = a;
a = temp;
[/CODE]

Without temp variable swap:
Edit: Alternatively, From https://stackoverflow.com/questions...rdized-method-to-swap-two-variables-in-python is your answer. However, the spoiler has the code in it.
Python:
a,b = b,a
 
Last edited:
To create variables you do this:
Python:
a = str("Hi") ## A string
a = int(10) ## A integer
a = float(True) ## A float
 

New Threads

Buy us a coffee!

Back
Top Bottom